1

i have 3 ggplots (g1,g2,g3) and would like to shows them arranged so that g1 is larger and inbetween the other 2.

g1 =ggplot(data = data.frame(x = 1 ,y =1), aes(x = x, y = 1))+geom_point() g2 = ggplot(data = data.frame(x = 1 ,y =1), aes(x = x, y = 1))+geom_point() g3 = ggplot(data = data.frame(x = 1 ,y =1), aes(x = x, y = 1))+geom_point() library(grid) lay <- rbind(c(2,1,1,1,3), c(2,1,1,1,3)) gs = grobTree( ggplotGrob(g1), ggplotGrob(g2), ggplotGrob(g3) ) grid.arrange(grobs = gs, layout_matrix = lay) 

I was looking here: https://cran.r-project.org/web/packages/gridExtra/vignettes/arrangeGrob.html but I get an error. Any idea about the proper syntax?

Error in gtable_add_grob(gt, grobs, t = positions$t, b = positions$b, : Not all inputs have either length 1 or same length same as 'grobs' 
1

1 Answer 1

2

I have never use the grobTree function but replace it with a list and it works

gs = list(ggplotGrob(g1), ggplotGrob(g2), ggplotGrob(g3)) grid.arrange(grobs = gs, layout_matrix = lay) 

this is the result, as you want I think enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

For separate plots: grid.arrange(g1, g2, g3, widths=c(1,3,1)). Or, if the plots are already in a list (for example, gs=list(g1,g2,g3)): grid.arrange(grobs=gs, widths=c(1,3,1)).
@eipi10 i wast sure if i had to us the ggplotGrob in the list but i guess not

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.