Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change font in textGrob

Tags:

fonts

r-grid

I am hoping someone can help out with custom text labels in grid.arrange. I have four plots that I am arranging in a column with a shared legend below. I am trying to change the font of the "left" label in grid.arrange but I cannot figure out how textGrob works for this. My current code (with p1-p4 as ggplot objects) is:

windowsFonts(Georgia=windowsFont("TT Georgia"))

plots <- list(p1, p2, p3, p4)
g <- ggplotGrob(plots[[1]])
leftText <- textGrob("Percent Savings", rot=90, gp=gpar(font="Georgia"))
grid.arrange(
             do.call(arrangeGrob, c(plots, nrow=4)),
             left    = leftText,
             top     = " ",
             ncol    = 1,
             heights = c(8))

The font in the legend changes correctly, but the left-side font remains the default. I have tried both font="Georgia" and family="Georgia". Any ideas how I can get this to work?

Edit: For anyone else having this problem, I finally stumbled across an answer, in textGrob the command is not font or family. It is, in fact, fontfamily.

like image 843
EsotericPunk Avatar asked Mar 09 '16 21:03

EsotericPunk


1 Answers

As the OP noted, the grid parameter is called fontfamily,

 grid.text("haha", gp=gpar(fontfamily = "Zapfino", cex=5))

enter image description here

like image 123
baptiste Avatar answered Nov 19 '22 06:11

baptiste