Reputation: 288
When plotting "effects" from the {effects} package, I'm unable to change font type to Times New Roman. In other plots (base or ggplot), I use the {extrafont} package, which works fine for me - but I was not able to work out the settings here and I need this because of journal guidelines.
Minimum reproducible example is provided here:
library(extrafont)
loadfonts(device="win")
windowsFonts(Times=windowsFont("TT Times New Roman"))
#
require(effects)
mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
data=Cowles, family=binomial)
eff.cowles <- allEffects(mod.cowles, xlevels=list(extraversion=seq(0, 24, 6)))
# Sample plot, yet I need all text to be Times New Roman
plot(eff.cowles$sex)
#
# This, however, does not change the font as expected...
plot(eff.cowles$sex, family = "Times New Roman" )
#
# Just for comparison - here, the fonts (title, axes, etc.) change properly
hist(Cowles$neuroticism, family = "Times New Roman")
Maybe I'm missing something simple, but was not able to fix this. Any suggestions would be highly appreciated.
Upvotes: 3
Views: 1239
Reputation: 288
So, after some additional searching, it turns out that {effects} plot is {lattice} based and the following code does what I need (run after the effects are calculated):
require(lattice)
trellis.device()
trellis.par.set(list(axis.text = list(font = 6, cex=2)))
trellis.par.set(list(par.ylab.text = list(font = 6, cex=2)))
trellis.par.set(list(par.xlab.text = list(font = 6, cex=2)))
trellis.par.set(list(par.main.text = list(font = 6, cex=2)))
trellis.par.set(grid.pars = list(fontfamily = "serif"))
plot(eff.cowles$sex)
dev.off()
Upvotes: 3