我制作了这幅图,基本上描述了从Cox回归和某个肿瘤中预测的1年和3年的进展风险,作为累积剂量的函数。
问题:--我已经使用ggarrange()合并了这两幅图,但不幸的是,由于对此图使用了theme(legend.position = "bottom"),而对于下块则使用了show.legend = F。因此,y-axes有不同的高度。
问题:是否有一种方法可以手动调整排列好的地块的高度,以获得y-axes的相同高度,同时保留上面情节的图例?如果解决了这个问题,我愿意使用其他的合并方法。

我的剧本:
# Defining theme
theme <- theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_line(colour = "gray95"),
panel.grid.minor = element_line(colour = "gray95"),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(color = "grey20", size =16),
axis.title.x = element_text(color = "grey20", size = 16, face="bold", margin=ggplot2::margin(t=10)),
axis.text.y = element_text(color = "grey20", size = 16),
axis.title.y = element_text(color = "grey20", size = 17, face="bold", margin=ggplot2::margin(r=10)),
legend.key = element_rect(fill = "white"),
plot.title = element_text(color = "grey20", size = 20, face="bold",hjust = 0),
plot.subtitle = element_text(hjust = 0.5),
legend.text=element_text(size=17), legend.title=element_text(size=20)) 和
ggarrange(
ggplot(df_yr1, aes(x = total.ssa, y = value, colour = name, group = name)) +
theme + theme(axis.title.x = element_text(size=15),
plot.title = element_text(hjust = 0.5, size=20),
plot.subtitle=element_text(size=18, hjust=0.5),
legend.position = "bottom") +
ggtitle(label = "1 year: predicted risk of progression") +
geom_area(aes(fill = name), position = "stack", alpha = 0.15) +
geom_line(colour = "white", size = 3, position = "stack") +
geom_line(position = "stack", show.legend = F) +
geom_point(position = "stack", data = df_yr1[c(1:3, -2:0 + nrow(df_yr1)), ],
shape=21, fill="white", stroke=1, size=3) +
scale_fill_manual(values = c("#E1B930", "#8B3A62", "#6DBCC3"),
labels = c("WHO-3", "WHO-2", "WHO-1"),
name="",
guide = guide_legend(reverse = TRUE)) +
scale_colour_manual(values = c("#E1B930", "#8B3A62", "#6DBCC3"),
labels = c("WHO-3", "WHO-2", "WHO-1"),
name="",
guide = guide_legend(reverse = TRUE)) +
scale_y_continuous(breaks = seq(0, 1, .2),
labels = paste0(seq(0, 100, 20), "%"),
name="",
limits = c(0, 1)) +
scale_x_continuous(breaks = seq(0, 1000, 200),
limits = c(0, 1000),
name="Somatostatin analogues (cumulative mg)\n"),
ggplot(df_yr3, aes(x = total.ssa, y = value, colour = name, group = name)) +
theme + theme(axis.title.x = element_text(size=15),
plot.title = element_text(hjust = 0.5, size=20),
plot.subtitle=element_text(size=18, hjust=0.5)) +
ggtitle(label = "\n3 years: predicted risk of progression") +
geom_area(aes(fill = name), position = "stack", alpha = 0.15, show.legend = F) +
geom_line(colour = "white", size = 3, position = "stack", show.legend = F) +
geom_line(position = "stack", show.legend = F) +
geom_point(position = "stack", data = df_yr3[c(1:3, -2:0 + nrow(df_yr3)), ],
shape=21, fill="white", stroke=1, size=3, show.legend = F) +
scale_fill_manual(values = c("#E1B930", "#8B3A62", "#6DBCC3"),
labels = c("WHO-3", "WHO-2", "WHO-1"),
name="",
guide = guide_legend(reverse = TRUE)) +
scale_colour_manual(values = c("#E1B930", "#8B3A62", "#6DBCC3"),
labels = c("WHO-3", "WHO-2", "WHO-1"),
name="",
guide = guide_legend(reverse = TRUE)) +
scale_y_continuous(breaks = seq(0, 1, .2),
labels = paste0(seq(0, 100, 20), "%"),
name="",
limits = c(0, 1)) +
scale_x_continuous(breaks = seq(0, 1000, 200),
limits = c(0, 1000),
name="Somatostatin analogues (cumulative mg)\n"),
ncol = 1, nrow = 2
)我的数据
df_yr1 <- structure(list(total.ssa = c(0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15,
15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20,
21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26,
26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31,
31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36,
37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42,
42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, 47, 47,
47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 52, 52, 52,
53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 58,
58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63,
63, 64, 64, 64, 65, 65, 65, 66, 66), name = structure(c(1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L), .Label = c("who3", "who2", "who1"), class = "factor"),
value = c(0.029, 0.064, 0.907, 0.03, 0.064, 0.906, 0.03,
0.065, 0.905, 0.031, 0.065, 0.904, 0.031, 0.066, 0.903, 0.032,
0.066, 0.902, 0.032, 0.067, 0.901, 0.033, 0.068, 0.9, 0.033,
0.068, 0.899, 0.034, 0.069, 0.897, 0.034, 0.069, 0.896, 0.035,
0.07, 0.895, 0.035, 0.07, 0.894, 0.036, 0.071, 0.893, 0.036,
0.071, 0.892, 0.037, 0.072, 0.891, 0.038, 0.073, 0.89, 0.038,
0.073, 0.888, 0.039, 0.074, 0.887, 0.039, 0.074, 0.886, 0.04,
0.075, 0.885, 0.041, 0.075, 0.884, 0.041, 0.076, 0.883, 0.042,
0.077, 0.881, 0.042, 0.077, 0.88, 0.043, 0.078, 0.879, 0.044,
0.078, 0.878, 0.044, 0.079, 0.877, 0.045, 0.079, 0.875, 0.046,
0.08, 0.874, 0.046, 0.08, 0.873, 0.047, 0.081, 0.872, 0.048,
0.082, 0.87, 0.048, 0.082, 0.869, 0.049, 0.083, 0.868, 0.05,
0.083, 0.867, 0.05, 0.084, 0.865, 0.051, 0.084, 0.864, 0.052,
0.085, 0.863, 0.052, 0.086, 0.861, 0.053, 0.086, 0.86, 0.054,
0.087, 0.859, 0.055, 0.087, 0.858, 0.055, 0.088, 0.856, 0.056,
0.088, 0.855, 0.057, 0.089, 0.854, 0.057, 0.089, 0.852, 0.058,
0.09, 0.851, 0.059, 0.091, 0.85, 0.06, 0.091, 0.848, 0.061,
0.092, 0.847, 0.061, 0.092, 0.846, 0.062, 0.093, 0.844, 0.063,
0.093, 0.843, 0.064, 0.094, 0.841, 0.065, 0.094, 0.84, 0.065,
0.095, 0.839, 0.066, 0.095, 0.837, 0.067, 0.096, 0.836, 0.068,
0.096, 0.834, 0.069, 0.097, 0.833, 0.069, 0.098, 0.832, 0.07,
0.098, 0.83, 0.071, 0.099, 0.829, 0.072, 0.099, 0.827, 0.073,
0.1, 0.826, 0.074, 0.1)), row.names = c(NA, -200L), class = c("tbl_df",
"tbl", "data.frame"))和
df_yr3 <- structure(list(total.ssa = c(0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15,
15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20,
21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26,
26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31,
31, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36,
37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42,
42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, 47, 47,
47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 52, 52, 52,
53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 58,
58, 58, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63,
63, 64, 64, 64, 65, 65, 65, 66, 66), name = structure(c(1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L), .Label = c("who3", "who2", "who1"), class = "factor"),
value = c(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0.001, 0.999, 0, 0.001,
0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999,
0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001,
0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999,
0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001,
0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999,
0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001,
0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999,
0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001,
0.999, 0, 0.001, 0.999, 0, 0.001, 0.999, 0, 0.001, 0.999,
0, 0.001, 0.998, 0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002,
0.998, 0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002, 0.998,
0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002,
0.998, 0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002, 0.998,
0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002, 0.998, 0, 0.002,
0.997, 0, 0.002)), row.names = c(NA, -200L), class = c("tbl_df",
"tbl", "data.frame"))发布于 2021-05-01 18:23:12
更新: OP对patchwork解决方案的需求。
将您的情节命名为p1和p2:
library(patchwork)
p1 + p2 + plot_layout(ncol=1,heights=c(2,2))

原始答案:尝试如下:在代码末尾替换
ncol = 1, nrow = 2
通过
heights = c(4, 3.5), nrow = 2, align = "v"
我无法复制您的情节:但是有了上面的代码,您可以调整情节的高度。仅仅是为了展示情节的高度:

https://stackoverflow.com/questions/67349446
复制相似问题