3

Creating a plot where the y-axis has two lines. I'm using the atop function as follows:

plot + ylab(expressions(atop("Line 1","Line 2")))

Wondering whether it would be possible to change line 1's font size i.e., make it larger than line 2?

Thanks!

CYT
  • 189
  • 1
  • 1
  • 4

2 Answers2

3

The is a mechanism to make specific sections of the fonts smaller using the plotmath scriptstyle function. There's also another make-even-smaller version of it. Look at the ?plotmath page for a full list of plotmath functions. I don't know of a plotmath strategy for making fonts larger.

plot + ylab(expression( atop(Line~1, 
                             scriptstyle(Line~2))
           ))

Note there is no expressions function and that I converted your text to a real R expression. You might look at the theme() settings for the element_text features for axis.title.y to increase the text size.

plot + ylab(expression( atop( Line~ 1,
                             scriptstyle( Line~ 2) ))) + 
       theme(axis.title.y = element_text( size = rel(2) ) )
IRTFM
  • 258,963
  • 21
  • 364
  • 487
0

Other than plotmath, you could draw the text directly using grid functions:

library("gridExtra")
gt <- grobTree(ggplotGrob(plot + ylab("")), textGrob("Line 1", 0.01, 0.5, rot = 90, gp = gpar(fontsize = 18)), textGrob("Line 2", 0.025, 0.5, rot = 90, gp = gpar(fontsize = 10)))
plot.new()
grid.draw(gt)
Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52