0

Here is my original question:

In ggplot2, how can I set y-labs separately for double-panel plots?

**And after I used the method given by "baptiste", which is also the correct anwser, and as soon as I change the word size bigger, part of the word has been curtained by the panel's white margin, so, how to fix this problem? **

Here is the code revised of his code:

g = ggplotGrob(p)
g = gtable_add_grob(g, list(textGrob("upper panel", just = "top", rot=90, gp=gpar(fontsize=20)), 

                         textGrob("lower panel", just = "top", rot=90, gp=gpar(fontsize=20))), 

                         t = c(3,5), l = 1)
g$widths[[1]] = unit(1, "line")
grid.newpage()
grid.draw(g)

Here is the plot: enter image description here

Community
  • 1
  • 1
Ping Tang
  • 415
  • 1
  • 9
  • 20

1 Answers1

1

Well, when you're changing fontsize like that, try making the width wider. Or in this case, set it to a proportion of the grobheight

g = ggplotGrob(p)
g = gtable_add_grob(g, 
    ng<-list(textGrob("upper panel", just = "top", rot=90, gp=gpar(fontsize=20)), 
    textGrob("lower panel", just = "top", rot=90, gp=gpar(fontsize=20))), 
    t = c(3,5), l = 1
)
g$widths[[1]] = unit(.5, "grobheight", ng)
grid.newpage()
grid.draw(g)

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295