Cauder
Cauder

Reputation: 2597

How do I change the font for geom_text in ggplot?

I'd like to set the font for geom_text to Roboto condensed.

I tried to do it wih hrbrbr themes, but it doesn't appear to be in roboto condensed.

I know this thread has an answer, but it requires changing the font system wide.

Can I apply roboto condensed to a ggplot chart for only the geom_text labels?

Upvotes: 2

Views: 2005

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173803

I don't think the answer you have linked does change the font system-wide. It just gives you the ability to access a font. I'll demonstrate here using a handwriting font to make this very obvious:

windowsFonts(Script = windowsFont("Edwardian Script ITC"))

library(ggplot2)

ggplot(mtcars, aes(disp, mpg)) + 
  geom_text(aes(label = rownames(mtcars)), family = "Script") 

You can see the axis labels and markers are not affected.

Created on 2020-05-15 by the reprex package (v0.3.0)

Upvotes: 2

Related Questions