Search code examples
rggplot2gridextrar-grid

How to combine two ggplots with one rotated?


How do you combine two ggplots g1 and g2 with one on the left and one on the right, 90° rotated (only the right one) ?

I have already looked at grid and gridExtra package but I don't find my way through all of this.


Solution

  • Some adjustments might be necessary for the width and height of the second plot, but this seems to work:

    p <- qplot(1:10)
    
    library(grid)
    grid.newpage()
    print(p, vp=viewport(0, 0, width = unit(0.5, "npc"), just = c('left', 'bottom')))
    print(p, vp=viewport(0.5, 0, angle = 90, height = unit(0.8, "npc"), width = 0.55, just = c('left', 'top')))
    

    enter image description here