1

I am trying to convert the font in ggplot to Times New Roman. I have loaded in the 'extrafont' package. Please see the example below. I'm not sure why this doesn't work.


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)
  )
JC3019
  • 363
  • 1
  • 9

1 Answers1

0

Solved: Key point is to run: font_import() followed by loadfonts(device="win")

JC3019
  • 363
  • 1
  • 9