3

I am trying to graph a 2-way interaction using interact_plot function in interactions. How do I change the font size to Times New Roman?

Here is my code:

interact_plot(Interac2, pred = SA, modx = RPF, alpha = .05, legend.main = "RP", x.label = "EXB", y.label = "NORCA")
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
TaylorT
  • 31
  • 3

1 Answers1

2

First, I noticed that you mentioned interact_plot in jtools. The documentation there says that this function has been deprecated and moved to package interactions (which I also edited into your question). Looking at the source code on GitHub it shows that the final object is a ggplot object. Which is great, because you can modify "theme" of this object after it is plotted. You modify the theme and replot it et voila.

Since I'm on Windows and needed tips on how to modify font to TNY, I found this post. Some of the examples in interact_plot didn't work for me, but I did manage to modify the one that did.

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

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197