I can't set my fonts in geom_text. Here is what I tried:
labels_test<-data.frame(a=c("a","b","c"),b=c(1:3),c=c(3:1)) # works ggplot () + geom_text(data=labels_test,aes(b,c,label=a),color="blue") # does not work: ggplot () + geom_text(data=labels_test,aes(b,c,label=a),color="blue",family="Times") # error message: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,: # Font family not found in Windows font database
I already imported all fonts as indicated here. Any ideas what is still going wrong?
ggplot allows you to change the font of each part of the figure: you just need to know the correct option to modify in the theme. (For a full list of customizable components of the theme, see this documentation.)
The default font size of geom_text() is 3.88. You can change the size using the size argument in geom_text() for a single plot. If you want to use the same updated size, you can set this with update_geom_defaults() , e.g. update_geom_defaults("text", list(size = 6)) .
I would try"
windowsFonts(Times=windowsFont("TT Times New Roman"))
In doing this your specifying explicitly the Windows Font mapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With