Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change fonts in ggplot/geom_text

Tags:

r

ggplot2

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?

like image 522
Joschi Avatar asked Feb 06 '13 16:02

Joschi


People also ask

Can you change the font in ggplot2?

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

How do I change the size of text in Geomation?

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


1 Answers

I would try"

windowsFonts(Times=windowsFont("TT Times New Roman")) 

In doing this your specifying explicitly the Windows Font mapping.

like image 166
user1317221_G Avatar answered Oct 12 '22 02:10

user1317221_G