我正在尝试编写一个函数(但没有成功),该函数将自动组装使用
该函数将接受以下输入:
任何想法?
patchwork
绘制的ggplot图表列表。该函数将接受以下输入:
- 行数
- 列数
- 带有图表的主列表
library(tidyverse)
library(patchwork)
p1 <- mtcars %>% ggplot() + geom_bar(aes(mpg))
p2 <- mtcars %>% ggplot() + geom_bar(aes(cyl))
p3 <- mtcars %>% ggplot() + geom_bar(aes(disp))
p4 <- mtcars %>% ggplot() + geom_bar(aes(hp))
p5 <- mtcars %>% ggplot() + geom_bar(aes(drat))
p6 <- mtcars %>% ggplot() + geom_bar(aes(wt))
plot_list <- list(mpg = p1,
cyl = p2,
disp = p3,
hp = p4,
drat = p5,
wt = p6)
# Function inputs
no_of_rows = 2
no_of_col2 = 3
master_list_with_plots = org_plot
#Function output would be org_plot below
org_plot <- plot_list[["mpg"]] + plot_list[["cyl"]] + plot_list[["disp"]] +
plot_list[["hp"]] + plot_list[["drat"]] + plot_list[["wt"]]
任何想法?
patchwork::wrap_plots(plot_list, no_of_rows, no_of_col2)
patchwork::wrap_plots(plot_list, no_of_rows, no_of_col2)
- Ronak Shah