我有以下圖,我使用 ggplot2 和拼湊而成的面板圖。每一行都對不同的目標資料集進行預測,所以我認為為每一行設定一個標題可能會有所幫助,我剛剛創建了一個空的標題ggplot annotate()
以下是它目前的樣子:

示例代碼
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(
)
問題
如何減少title1和title2與其他圖之間的空間?
期望輸出:

uj5u.com熱心網友回復:
title1 / (p1 | p2) /
title2 / (p3 | p4)
plot_layout(heights = c(1,6,1,6))
....

你可以在你的調整文字大小title1,并title2讓這些與其他文本更為一致。這里有size = 5:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/315907.html
