如何在特效包图表中更改字体类型

3
当使用{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个回答

2

所以,在进一步搜索后,发现 {effects} 绘图是基于 {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()

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