# devtools::install_github("thomasp85/patchwork")
# devtools::install_github("jbengler/multipage")
library(tidyverse)
library(patchwork)
library(multipage)
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
)
plots <- list(p1, p2, p3, p4, p4, p3, p2, p1)
#>
#> [[2]]
plots %>% multipage_plots(ncol = 2, nrow = 2,
width = unit(20, "mm"), height = unit(20, "mm"))
#> [[1]]
#>
#> [[2]]
data_exprs_sel <-
data_exprs %>%
nest(data = -external_gene_name) %>%
filter(row_number() %in% c(1:4,20:23)) %>%
unnest(cols = c(data))
p5 <-
data_exprs_sel %>%
ggplot(aes(group, expression, color = sample_type)) +
geom_boxplot(width = 0.6, position = position_dodge(width = 0.8))
p5
#>
#> [[2]]
p5 %>% multipage_facets(facet_by = external_gene_name, ncol = 2, nrow = 2,
width = unit(35, "mm"), height = unit(35, "mm"))
#> [[1]]
#>
#> [[2]]
plots %>%
multipage_plots(ncol = 2, nrow = 2, width = unit(20, "mm"), height = unit(20, "mm")) %>%
save_multipage("test.pdf")
plots %>%
multipage_plots(ncol = 6, nrow = 6, width = unit(40, "mm"), height = unit(40, "mm")) %>%
save_multipage("test.pdf")
plots %>%
multipage_plots(ncol = 3, nrow = 3) %>%
save_multipage("test.pdf")
plots %>%
multipage_plots(ncol = 6, nrow = 6) %>%
save_multipage("test.pdf")
p1 %>%
multipage_facets(facet_by = cyl, ncol = 1, nrow = 1, width = unit(20, "mm"), height = unit(20, "mm")) %>%
save_multipage("test.pdf")
p1 %>%
multipage_facets(facet_by = cyl, ncol = 2, nrow = 2, width = unit(40, "mm")) %>%
save_multipage("test.pdf", height = 200)
p1 %>%
multipage_facets(facet_by = cyl, ncol = 2, nrow = 2, width = unit(40, "mm")) %>%
save_multipage("test.pdf")
p1 %>%
multipage_facets(facet_by = cyl, ncol = 2, nrow = 2, width = unit(20, "mm"), height = unit(20, "mm")) %>%
save_multipage("test.png")
p1 %>%
multipage_facets(facet_by = cyl, ncol = 2, nrow = 2) %>%
save_multipage("test.png")
save_multipage(p1, "test.pdf")
save_multipage(list(p1, p2, p3), "test.pdf")
save_multipage(list(patchwork1, patchwork2, patchwork3), "test.pdf")
save_multipage(patchwork1, "test.pdf")
save_multipage(patchwork2, "test.pdf")
save_multipage(patchwork3, "test.pdf")
save_multipage(list(p1, p2, p3), "test.pdf")
save_multipage(list(p1, p2, p3), "test.png")
save_multipage(list(p1, p2, p3), "test.png", burst_to_multiple_files = TRUE)
save_multipage(list(patchwork1, patchwork2, patchwork3), "test.pdf")
save_multipage(list(patchwork1, patchwork2, patchwork3), "test.png")
save_multipage(list(patchwork1, patchwork2, patchwork3), "test.png", multiple_files = TRUE)
multipage:::get_layout_size(p1)
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 1 x 2
#> width height
#> <lgl> <lgl>
#> 1 NA NA
#>
#> $max
#> width height
#> NA NA
multipage:::get_layout_size(list(p1, p2, p3))
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 3 x 2
#> width height
#> <lgl> <lgl>
#> 1 NA NA
#> 2 NA NA
#> 3 NA NA
#>
#> $max
#> width height
#> NA NA
multipage:::get_layout_size(list(patchwork1, patchwork2, patchwork3))
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 3 x 2
#> width height
#> <dbl> <dbl>
#> 1 226. 70.3
#> 2 406. 45.3
#> 3 NA NA
#>
#> $max
#> width height
#> NA NA
multipage:::get_layout_size(patchwork1)
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 1 x 2
#> width height
#> <dbl> <dbl>
#> 1 226. 70.3
#>
#> $max
#> width height
#> 226.42008 70.28865
multipage:::get_layout_size(patchwork2)
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 1 x 2
#> width height
#> <dbl> <dbl>
#> 1 406. 45.3
#>
#> $max
#> width height
#> 406.42008 45.28865
multipage:::get_layout_size(patchwork3)
#> $units
#> [1] "mm"
#>
#> $pages
#> # A tibble: 1 x 2
#> width height
#> <lgl> <lgl>
#> 1 NA NA
#>
#> $max
#> width height
#> NA NA