Thomas Lin Pedersen简直是个天才，最近`patchwork`动作很大，看到我都准备转投它的怀抱，把旧爱`cowplot`给扔了。

``````library(ggplot2)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('图一')

p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear)) +
ggtitle('图二')

p3 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('图三')

p4 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
facet_wrap(~cyl) +
ggtitle('图四')
``````

## 拼图专用空白

`plot_spacer()`来填空白，一如既往地用`+`号来拼：

``````p1 + plot_spacer() +
p2 + plot_spacer() +
p3 + plot_spacer()
``````

## 拼图语法

`+`号大家都知道，按照row来拼，用`/`，按照column来拼，用`|`，这个语法绝了！而且一堆`+`号，在拼图多的时候也很乱，用`/``|`配以`()`和换行，可读性太强了。

``````(p2 / p3 ) | p1
``````

## 控制细节

`+``/``|`毕竟是语法糖，要控制细节，全在`plot_layout`里。

``````p1 + p2 + p3 + p4 +
plot_layout(widths = c(3, 1))
``````

## 超越网格

``````layout <- "
##BBBB
AACCDD
##CCDD
"
p1 + p2 + p3 + p4 +
plot_layout(design = layout)
``````

``````layout <- c(
area(t = 2, l = 1, b = 5, r = 4),
area(t = 1, l = 3, b = 3, r = 5)
)
p1 + p2 +
plot_layout(design = layout)
``````

## 控制legend

``````g <- ggplot(mtcars) +
geom_point(aes(mpg, disp, colour = mpg, size = wt))
g1 <- g + ggtitle("图一")
g2 <- g + scale_colour_viridis_c() + ggtitle("图二")

(p3 | (g1 / g2)) +
plot_layout(guides = 'collect')
``````

``````g1 + p2 + p3 +
guide_area() +
plot_layout(guides = 'collect')
``````