使用interactions包中的interact_plot更改图表的字体。

3

我想使用 interactions 中的 interact_plot 函数绘制一个二元交互图。如何将字体大小更改为 Times New Roman?

这是我的代码:

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

2
首先,我注意到你提到了jtools中的interact_plot。那里的文档说这个函数已经被弃用并移到了interactions包中(我也把它编辑到了你的问题中)。查看GitHub上的源代码,显示最终对象是一个ggplot对象。这很好,因为你可以在绘制后修改此对象的“主题”。你可以修改主题并重新绘制它,就可以得到想要的结果。
由于我使用的是Windows系统,需要知道如何将字体修改为TNY,我找到了这篇文章。其中一些interact_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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接