在R中的交互图中更改字体系列

时间:2015-09-29 21:45:10

标签: r plot fonts ggplot2

我正在使用sjPlot - 一个构建ggplot2的软件包,我是新手 - 我正在尝试将字体系列更改为Times New Roman。使用示例代码:

require(sjPlot); require(effects)
fit <- lm(weight ~ Diet * Time, data = ChickWeight)
sjp.int(fit, type = "eff")

但是,当我尝试添加诸如以下的参数时:

theme(text = element_text(size = 14, family = "Times New Roman")) 

它不起作用;当我尝试在sjp.setTheme()中输入类似代码时也不会这样做。有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:2)

sjp.SetTheme不允许您指定字体系列(您将在arg列表中发现它丢失)。我不想跋涉all of this code来弄清楚如何改变该函数以给出字体系列规范,但我能够通过theme_set改变字体系列:

library(sjPlot)
library(effects)
library(ggplot2)
data("ChickWeight")
fit <- lm(weight ~ Diet * Time, data = ChickWeight)

theme_set(theme_bw(base_family = 'AR BERKLEY'))
sjp.int(fit, type = "eff") 

enter image description here

theme_set(theme_bw(base_family = "Times New Roman"))
sjp.int(fit, type = "eff") 

enter image description here