我有两个地块。
第一个 (
big
) 应该充当“背景图”。small
) 应该是插图。
两幅图:
library(survminer)
library(survival)
library(patchwork)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
# Big plot
big <- ggsurvplot(
fit,
size = 1,
legend.labs = c("A", "B"),
ylim = c(0, 1),
linetype = "strata",
break.time.by = 365,
palette = c("#E7B800", "#2E9FDF"),
risk.table = TRUE,
risk.table.title = "No. at risk",
risk.table.height = 0.2,
fontsize = 6,
tables.theme = theme_cleantable()
)
# Small plot (inset)
small <- ggsurvplot(
fit,
size = 1,
legend.labs = c("A", "B"),
legend = "none",
ylab = "",
ylim = c(0.7, 1),
linetype = "strata",
xlim = c(0, 365),
break.time.by = 365,
palette = c("#E7B800", "#2E9FDF"),
fontsize = 6,
tables.theme = theme_cleantable()
)
我的尝试:
big_plot <- big$plot / big$table + plot_layout(heights = c(3, 0.5))
small_plot <- small$plot
combined <- big_plot + inset_element(small_plot, left = 0.2, bottom = 1, right = 0.95, top = 1, align_to = 'plot')
ggsave("combined.pdf", combined)