I am looking for a way to modify font types in ggplot. At the moment I would be happy enough to simply change fonts to the \'courier\' font family, but ultimately my goal is
This seems like the simplest solution, for my money.
Some play data in df, and made into a simple graph, "p", with nice long x and y labels, so we can see the font change:
df <- data.frame(A = rnorm(10), B = rnorm(10))
p = ggplot(data = df, aes(x = A, y = B)) + geom_point()
p = p + xlab("A long x-string so we can see the effect of the font switch")
p = p + ylab("Likewise up the ordinate")
And we view the default plot in whatever that font is:
p
Now we switch to Optima, adding some nice title and subtitle to bask in the glory of Optima:
label = "Now we switch to Optima"
subtitle = "Optima is a nice font: https://en.wikipedia.org/wiki/Optima#Usages"
And after all that, we print in the new font
# the only line you need to read:
p + theme(text = element_text(family = "Optima", , face = "bold"))
p = p + ggtitle(label = label, subtitle = subtitle)
p