I have my dummy data as:
x=1:7
y=1:7
df = data.frame(x=x,y=y)
bp <- vector("list", length = 4)
for (i in 1:4) {
bp[[i]] <- ggplot(df,aes(x,y))+geom_point()
}
I have my ggplot objects in a list called bp
with which I can generate a four-plot-grid as:
figure <- ggarrange(bp[[1]], bp[[2]], bp[[3]], bp[[4]],
labels = c("A", "B", "C", "D"),
ncol = 2, nrow = 2)
Now, I don't want to type bp[[1]]..bp[[4]]
and want to use something like
do.call(ggarrange, bp)
as you would do with function grid.arrange
like do.call(grid.arrange, bp)
. do.call(grid.arrange, bp)
doesn't show the panel labels so I would like to use ggarrange
and still would want to pass these arguments:
labels = c("A", "B", "C", "D"),
ncol = 2, nrow = 2
How can I use do.call
in this case? Is there a better way to do this?