Generate demo plots
# devtools::install_github("thomasp85/patchwork")
library(tidyverse)
library(patchwork)
library(bro)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear)) +
ggtitle('Plot 2')
p3 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
p4 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
ggtitle('Plot 4')
patchwork1 <-
p1 + p2 + p3 + p4 +
plot_layout(
ncol = 4,
widths = unit(c(50, 25, 50, 25), "mm"),
heights = unit(50, "mm"),
guides = "collect"
)
patchwork2 <-
p1 + p2 + p3 + p4 +
plot_layout(
ncol = 4,
widths = unit(c(50, 25, 50, 205), "mm"),
heights = unit(25, "mm"),
guides = "collect"
)
patchwork3 <-
p1 + p2 + p3 + p4 +
plot_layout(
ncol = 4
)
# test bro_ggsave_paged --------------------------------------------------
# bro_ggsave_paged(p1, "test.pdf")
# bro_ggsave_paged(list(p1, p2, p3), "test.pdf")
# bro_ggsave_paged(list(patchwork1, patchwork2, patchwork3), "test.pdf")
# bro_ggsave_paged(patchwork1, "test.pdf")
# bro_ggsave_paged(patchwork2, "test.pdf")
# bro_ggsave_paged(patchwork3, "test.pdf")
#
# bro_ggsave_paged(list(p1, p2, p3), "test.pdf")
# bro_ggsave_paged(list(p1, p2, p3), "test.png")
# bro_ggsave_paged(list(p1, p2, p3), "test.png", burst_to_multiple_files = TRUE)
#
# bro_ggsave_paged(list(patchwork1, patchwork2, patchwork3), "test.pdf")
# bro_ggsave_paged(list(patchwork1, patchwork2, patchwork3), "test.png")
# bro_ggsave_paged(list(patchwork1, patchwork2, patchwork3), "test.png", burst_to_multiple_files = TRUE)
# test bro_wrap_plots_paged -----------------------------------------------
plots <-
list(p1, p2, p3, p4, p4, p3, p2, p1)
plots %>% bro_wrap_plots_paged()
#> [[1]]



#>
#> [[2]]

plots %>% bro_wrap_plots_paged(ncol = 2, nrow = 2,
width = unit(20, "mm"), height = unit(20, "mm"))
#> [[1]]

#>
#> [[2]]

# plots %>% bro_wrap_plots_paged(ncol = 2, nrow = 2, width = unit(20, "mm"), height = unit(20, "mm")) %>%
# bro_ggsave_paged("test.pdf")
#
# plots %>% bro_wrap_plots_paged(ncol = 6, nrow = 6, width = unit(40, "mm"), height = unit(40, "mm")) %>%
# bro_ggsave_paged("test.pdf")
#
# plots %>% bro_wrap_plots_paged(ncol = 3, nrow = 3) %>%
# bro_ggsave_paged("test.pdf")
#
# plots %>% bro_wrap_plots_paged(ncol = 6, nrow = 6) %>%
# bro_ggsave_paged("test.pdf")
# test bro_facet_wrap_paged -----------------------------------------------
bro_data_exprs_sel <-
bro_data_exprs %>%
nest(data = -external_gene_name) %>%
filter(row_number() %in% c(1:4,20:23)) %>%
unnest(cols = c(data))
p5 <-
bro_data_exprs_sel %>%
ggplot(aes(group, expression, color = sample_type)) +
geom_boxplot(width = 0.6, position = position_dodge(width = 0.8))
p5


p5 %>% bro_facet_wrap_paged(facet_var = external_gene_name,
width = unit(20, "mm"), height = unit(20, "mm"))
#> [[1]]


#>
#> [[2]]

p5 %>% bro_facet_wrap_paged(facet_var = external_gene_name, ncol = 2, nrow = 2,
width = unit(35, "mm"), height = unit(35, "mm"))
#> [[1]]

#>
#> [[2]]

p1 %>% bro_facet_wrap_paged(facet_var = cyl, ncol = 1, nrow = 1, width = unit(20, "mm"), height = unit(20, "mm")) %>%
bro_ggsave_paged("test.pdf")
#> Device width was inferred from plot width
#> Device height was inferred from plot height
#> Saving 36 x 40 mm image
p1 %>% bro_facet_wrap_paged(facet_var = cyl, ncol = 2, nrow = 2, width = unit(40, "mm")) %>%
bro_ggsave_paged("test.pdf", height = 200)
#> Device width was inferred from plot width
#> Device height was provided as parameter 'height' to bro_ggsave_paged()
#> Saving 112 x 200 mm image
p1 %>% bro_facet_wrap_paged(facet_var = cyl, ncol = 2, nrow = 2, width = unit(40, "mm")) %>%
bro_ggsave_paged("test.pdf")
#> Device width was inferred from plot width
#> Device height was not defined - default device used
#> Saving 112 x 114 mm image
p1 %>% bro_facet_wrap_paged(facet_var = cyl, ncol = 2, nrow = 2, width = unit(20, "mm"), height = unit(20, "mm")) %>%
bro_ggsave_paged("test.png")
#> Device width was inferred from plot width
#> Device height was inferred from plot height
#> Saving 72 x 79 mm image
p1 %>% bro_facet_wrap_paged(facet_var = cyl, ncol = 2, nrow = 2) %>%
bro_ggsave_paged("test.png")
#> Device width was not defined - default device used
#> Device height was not defined - default device used
#> Saving 185 x 114 mm image