I want to combine several ggplot2 charts into one using cowplot::plot_grid()
. From its documentation:
?plot
Arguments
...
List of plots to be arranged into the grid. The plots can be objects of one of the following classes: ggplot, recordedplot, gtable, or alternative can be a function creating a plot when called (see examples).
So, If I input a list of ggplot2 objects to plot_grid()
, it should combine those plots into one, right?
So why won't this work?
p1 <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
p2 <- ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
theme(axis.text.x = element_text(angle=70, vjust=0.5))
list(p1, p2) %>%
map(plot_grid)