0

Using ggplot2, I want to apply a theme to the font for my y-axis label. The label is written as an expression:

 g <- g + theme(axis.title.y = element_text(face="bold", colour="#000000", 
          size=32), axis.text.y  = element_text(angle=0, vjust=0.5, size=24,
          colour="#000000")) + ylab(expression(paste("Bias (R"^"2"*")")))

This command does not alter the font size or make it bold on the axis label. However, if I change the axis label to a pure string:

    g <- g + ylab("blah")

Then I get a bold, size 32 blah. I suspect this has something to do with the way ggplot2 handles the expression, but would rather not use a string like "R^2" instead of the superscript. I can't seem to find good information about this online however.

Any suggestions?

John Doucette
  • 4,370
  • 5
  • 37
  • 61
  • It seems to work for me. Maybe try again in a clean R session? – joran Sep 16 '13 at 18:38
  • Hmm. No, after closer inspection, it still happens in a clean R session. It may help to put up a 32pt bold font on the x axis for reference, since at first it looked similar to me in the clean session. – John Doucette Sep 16 '13 at 18:45
  • Semi-duplicate of http://stackoverflow.com/questions/8281897/ggplot2-font-style-in-label-expression. The solution is to use ylab(expression(bold(Bias~(R^2)))) instead (i.e. the bold directive within expression) – John Doucette Sep 16 '13 at 19:02

0 Answers0