r - How to use with plot_grid from cowplot -
i want combine several ggplot2 charts 1 using cowplot::plot_grid()
. documentation:
?plot arguments ... list of plots arranged grid. plots can objects of 1 of following classes: ggplot, recordedplot, gtable, or alternative can function creating plot when called (see examples).
so, if input list of ggplot2 objects plot_grid()
, should combine plots one, right?
so why won't 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)
see documentation of map
(?map
), states that:
.x list or atomic vector. .f function, formula, or atomic vector.
it means function provided .f
applied every elements in .x
. following code
list(p1, p2) %>% map(plot_grid)
is same following code
plot_grid(p1) plot_grid(p2)
,which not want.
what want this
plot_grid(p1, p2)
or this
plot_grid(plotlist = list(p1, p2))
Comments
Post a Comment