[英]How to decrease spacing between subplots
I have the following plot, I use ggplot2 and patchwork for a panel plot. Each row makes predictions about different target datasets so I thought it could be helpful to have a title for each row, which I just created with an empty ggplot + annotate()
Here is how it currently looks:我有以下 plot,我使用 ggplot2 和面板 plot 的拼凑。每一行都对不同的目标数据集进行预测,所以我认为为每一行设置一个标题可能会有所帮助,我刚刚用一个空的
ggplot + annotate()
这是它目前的样子:
Code for the Example示例代码
library(ggplot2)
library(patchwork)
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")
ggplot() +
annotate(geom = "text", x = 1, y = 1, label = "Predictions on Dataset 1",size=8) +
theme_void() -> title1
ggplot() +
annotate(geom = "text", x = 1, y = 1, label = "Predictions on Dataset 2",size=8) +
theme_void() -> title2
title1 /
(p1 | p2) /
title2 /
(p3 | p4) +
plot_annotation(
tag_levels = list(c("","A.1) Model Name 1", "B.1) Model Name 2", "","A.2) Model Name 1", "B.2) Model Name 2")),
theme = theme(plot.title = element_text(size = 24))
) &
theme(
)
Question问题
How can I reduce the space between the title1
and title2
and the other plots?如何减少
title1
和title2
与其他地块之间的空间?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.