如何更改R绘图中标签的字体?

如何更改R绘图中标签的字体?,r,fonts,plot,ggplot2,R,Fonts,Plot,Ggplot2,有人知道我怎样才能在R中更改绘图标签的字体(改为“计算机现代”样式)吗 我使用以下命令在R中使用ggplot创建绘图: plot <- ggplot(df, aes(x = df$date, y = df$domain_count)) + geom_bar(fill = "dark blue", stat = "identity")+labs(x="Date", y="# of counts per month", title="names per month") plot提供了一个很好

有人知道我怎样才能在R中更改绘图标签的字体(改为“计算机现代”样式)吗

我使用以下命令在R中使用ggplot创建绘图:

plot <- ggplot(df, aes(x = df$date, y = df$domain_count)) + geom_bar(fill = "dark blue", stat = "identity")+labs(x="Date", y="# of counts per month", title="names per month")

plot提供了一个很好的例子

总而言之,您需要安装
extrafont
并使用
font\u install('fontcm')
获得“计算机现代”字体。然后,对于
ggplot
,您可以使用
主题
元素_文本
功能修改字体

例如:

p <- qplot(seq(5), seq(5)) +
  xlab("Made with CM fonts") + ylab("Made with CM fonts") +
  ggtitle("Made with CM fonts")

# With the new fonts
p + theme(text         = element_text(size=16, family="CM Roman"),
          axis.title.x = element_text(face="italic", family="CM Sans"),
          axis.title.y = element_text(face="bold", family= "CM Roman Greek"))

p看看我的答案: