wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
701 stars 84 forks source link

Labels in `plot_grid()` seemed not affected by `byrow` #199

Open evanliu3594 opened 7 months ago

evanliu3594 commented 7 months ago

Labels are always attached by row.

p_list <- mtcars %>% split(.$gear) %>% map(~ggplot(.x,aes(x = mpg, y = disp)) + geom_point())
plot_grid(plotlist = p_list, ncol = 2, labels = names(p_list), byrow = F)

image

p_list["4"]

image

Doubt-0KB commented 5 months ago

If you don't mind adding more code, you can write it like this.

p_list <- mtcars %>% split(.$gear) %>% map(~ggplot(.x,aes(x = mpg, y = disp)) + geom_point())
p_list_label <- c(t(matrix(c(names(p_list), rep(NA, (2 * 2) - length(p_list))), nrow = 2, byrow = FALSE)))
plot_grid(plotlist = p_list, ncol = 2, labels = p_list_label, byrow = F)

image

I wrote this code with reference to the code which is at line181 in plot_grid.R.

evanliu3594 commented 5 months ago

If you don't mind adding more code, you can write it like this.

p_list <- mtcars %>% split(.$gear) %>% map(~ggplot(.x,aes(x = mpg, y = disp)) + geom_point())
p_list_label <- c(t(matrix(c(names(p_list), rep(NA, (2 * 2) - length(p_list))), nrow = 2, byrow = FALSE)))
plot_grid(plotlist = p_list, ncol = 2, labels = p_list_label, byrow = F)

image

I wrote this code with reference to the code which is at line181 in plot_grid.R.

Thanks for your solution, I'd like to use it if I have to adjust the label order manually. 😄