使用interact_plot更改图的字体(包交互)

时间:2019-03-31 05:58:18

标签: r graph fonts

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

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

首先,我注意到您在interact_plot中提到了jtools。那里的文档说该功能已被弃用,并移至软件包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"))

enter image description here