How to turn ggplot into an album?

I have a ggplot series that I would like to arrange as shown below and inserted into a document processed through knitr . Instead of having a really small portrait figure, I would like it to rotate to the landscape so that it can fill the page as much as possible. Any ideas?

 library(ggplot2) library(grid) df <- data.frame(x = 1:100, y =rnorm(100)) plota <- ggplot(df, aes(x, y)) + geom_point(size = 4) pushViewport(viewport(layout = grid.layout(3, 5))) vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) print(plota, vp = vplayout(1:2, 1:2)) print(plota, vp = vplayout(1, 3)) print(plota, vp = vplayout(1, 4)) print(plota, vp = vplayout(1, 5)) print(plota, vp = vplayout(2, 3)) print(plota, vp = vplayout(2, 4)) print(plota, vp = vplayout(2, 5)) print(plota, vp = vplayout(3, 1)) print(plota, vp = vplayout(3, 2)) print(plota, vp = vplayout(3, 3)) print(plota, vp = vplayout(3, 4)) print(plota, vp = vplayout(3, 5)) 
+6
source share
1 answer

Easy to rotate a figure in LaTeX; you can use the angle=90 option as described in http://yihui.name/knitr/options ; see full example below:

 \documentclass{article} \begin{document} <<out.extra='angle=90'>>= library(ggplot2) library(grid) df <- data.frame(x = 1:100, y =rnorm(100)) plota <- ggplot(df, aes(x, y)) + geom_point(size = 4) pushViewport(viewport(layout = grid.layout(3, 5))) vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) print(plota, vp = vplayout(1:2, 1:2)) print(plota, vp = vplayout(1, 3)) print(plota, vp = vplayout(1, 4)) print(plota, vp = vplayout(1, 5)) print(plota, vp = vplayout(2, 3)) print(plota, vp = vplayout(2, 4)) print(plota, vp = vplayout(2, 5)) print(plota, vp = vplayout(3, 1)) print(plota, vp = vplayout(3, 2)) print(plota, vp = vplayout(3, 3)) print(plota, vp = vplayout(3, 4)) print(plota, vp = vplayout(3, 5)) @ \end{document} 
+6
source

Source: https://habr.com/ru/post/925482/


All Articles