Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

r - Can't change fonts in ggplot/geom_text

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would try"

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

In doing this your specifying explicitly the Windows Font mapping.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...