File: patchwork.R

package info (click to toggle)
r-cran-patchwork 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,640 kB
  • sloc: sh: 15; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(patchwork)

## -----------------------------------------------------------------------------
library(ggplot2)
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)) + 
  facet_wrap(~cyl) + 
  ggtitle('Plot 4')

## -----------------------------------------------------------------------------
p1 + p2

## -----------------------------------------------------------------------------
p1 + p2 + labs(subtitle = 'This will appear in the last plot')

## -----------------------------------------------------------------------------
p1 + p2 + p3 + p4

## -----------------------------------------------------------------------------
p1 + p2 + p3 + p4 + plot_layout(nrow = 3, byrow = FALSE)

## -----------------------------------------------------------------------------
p1 / p2

## -----------------------------------------------------------------------------
p1 | (p2 / p3)

## -----------------------------------------------------------------------------
(p1 | (p2 / p3)) + 
  plot_annotation(title = 'The surprising story about mtcars')

## -----------------------------------------------------------------------------
p1 + p2 + p3 + 
  plot_annotation(tag_levels = 'I')