如何更改效果包图中的字体类型

时间:2017-06-12 21:31:54

标签: r plot fonts

在绘制"效果"从{effects}包中,我无法将字体类型更改为Times New Roman。在其他情节(基础或ggplot)中,我使用{extrafont}包,这对我来说很好 - 但是我无法在这里设置设置,因为期刊指南我需要这个。

此处提供了最低可重现性示例:

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")

也许我错过了一些简单的东西,但却无法解决这个问题。任何建议都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

所以,经过一些额外的搜索后,事实证明{effects} plot是基于{lattice}的,下面的代码就是我需要的(在计算效果后运行):

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()