【问题标题】:Change the font of a graph with interact_plot (package interactions)使用 interact_plot 更改图形的字体(包交互)
【发布时间】:2019-08-21 15:02:13
【问题描述】:

我正在尝试使用interactions 中的interact_plot 函数绘制双向交互图。如何将字体大小更改为 Times New Roman?

这是我的代码:

interact_plot(Interac2, pred = SA, modx = RPF, alpha = .05, legend.main = "RP", x.label = "EXB", y.label = "NORCA")

【问题讨论】:

    标签: r graph fonts


    【解决方案1】:

    首先,我注意到您在jtools 中提到了interact_plot。那里的文档说此功能已被弃用并移至包interactions(我也将其编辑到您的问题中)。查看source code on GitHub 它表明最终对象是ggplot 对象。这很棒,因为您可以在绘制后修改该对象的“主题”。您修改主题并重新绘制它等等。

    由于我在 Windows 上并且需要有关如何将字体修改为 TNY 的提示,因此我找到了 this postinteract_plot 中的一些例子对我不起作用,但我确实设法修改了那个例子。

    library(interactions)
    library(extrafont)
    loadfonts(device = "win")
    
    fit <- lm(Income ~ HSGrad * Murder * Illiteracy, data = states)
    xy <- interact_plot(model = fit, pred = Murder, modx = Illiteracy, mod2 = HSGrad)
    xy + theme(axis.title = element_text(family = "serif"),
               legend.text = element_text(family = "serif"),
               legend.title = element_text(family = "serif"),
               strip.text = element_text(family = "serif"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-19
      • 2020-10-05
      • 2022-01-02
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      相关资源
      最近更新 更多