0

Does anybody know how can I change the font (to "computer modern" style ) for the labels of my plot in R?

I have the below command to create the plot using ggplot in R:

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")
UserYmY
  • 8,034
  • 17
  • 57
  • 71
  • Have a look at my answer here: http://stackoverflow.com/questions/1890215/getting-r-plots-into-latex/35989420#35989420 – Augustin Mar 14 '16 at 13:53

1 Answers1

2

An excellent example is provided here.

Summarizing, you need to install extrafont and use font_install('fontcm') to get the 'Computer Modern' fonts. Then with respect to ggplot you can use the theme and element_text functions to modify fonts.

For example:

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"))

Where the title is 'Computer Modern' and the axis titles are CM Sans and CM Roman Greek with italic and bold typeface.

cdeterman
  • 19,630
  • 7
  • 76
  • 100