【问题标题】:Change font in ggplot [duplicate]更改ggplot中的字体[重复]
【发布时间】:2020-01-19 06:02:14
【问题描述】:

我正在尝试将 ggplot 中的字体转换为 Times New Roman。我已经加载了“extrafont”包。请看下面的例子。我不确定为什么这不起作用。


mat1 <- data.frame(matrix(nrow =10, ncol =4))
colnames(mat1) = c("Date", "Cluster 1", "Cluster 2", "Cluster 3")
date.start = as.Date("2000-01-01")
date.end = as.Date("2000-10-01")
date = seq(from = date.start, to = date.end, by = "month")
mat1[,1] = date
mat1[,2:4] = rnorm(30,0,1)





library(extrafont)
mat1 <- mat1 %>% 
  tidyr::gather(cluster, value, `Cluster 1`:`Cluster 3`)
mat1 %>% ggplot(aes(x= Date, y = value)) + 
  geom_line(aes(colour = cluster, linetype = cluster), size =1.25) +
  scale_colour_manual("",
                      values = c("Cluster 1" = "darkred", "Cluster 2" ="steelblue","Cluster 3" = "black"),
                      breaks = c("Cluster 1", "Cluster 2", "Cluster 3")) +
  scale_linetype_manual("",
                        values = c("solid", "twodash", "longdash"),
                        breaks = c("Cluster 1", "Cluster 2", "Cluster 3")) +
  xlab("Date") + ylab("Average Coefficient") + ggtitle("Market Factor") +     theme_classic() +
  theme(
    text = element_text(family = "Times"),
    plot.title = element_text(color = "black", size = 12, face = "bold", hjust = 0.5),
    axis.title = element_text(size = 12)
  )

【问题讨论】:

标签: r ggplot2


【解决方案1】:

已解决:关键点是运行:font_import() 后跟loadfonts(device="win")

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2018-09-24
    • 2014-11-15
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多