R survminer::ggsurvplot 轴标签和轴标题之间的距离

问题描述 投票:0回答:1

可重现的例子:

require(survival)
require(survminer)
require(ggplot2)

set.seed(42)

a <- c(32,291,545, 44,3,792,352, 20,615,169, 61,156, 88,863,255, 33,132,5,
       63,8,964,831, 55,133, 12, 54,261,867, 17, 12,699,233,251,446, 43,223, 
       374, 75, 34, 69,120, 84,134,8,806,8, 48, 86,211, 2436, 61, 81, 87, 12, 
       838, 34, 17,141, 44,155,128,6, 29, 16, 16, 34,130,430,325, 41, 28, 53,
       32,291,545, 44,3,792,352, 20,615,169, 61,156, 88,863,255, 33,132,5,
       63,8,964,831, 55,133, 12, 54,261,867, 17, 12,699,233,251,446, 43,223,
       86, 54,3,630, 93,699, 25,746,6, 46, 22, 60,395,402,151, 26, 38,125, 
       75, 34, 69,120, 84,134,8,806,8, 48, 86,211, 2436, 61,
       191, 49, 59,6, 34, 56,2, 96, 422, 45, 70)

b <- sample(c("Alpha", "Beta", "Gamma"), length(a), replace = T)
c <- sample(0:1, length(a), replace = T)
df <- data.frame(a, b, c)

df$b <- factor(df$b, levels = c("Alpha", "Beta", "Gamma"))
avg <- survfit(Surv(time = a, event = c) ~ 1, data = df)
surv_b <- survfit(Surv(time = a, event = c) ~ b, data = df)
surv_comb <- list(surv_b, avg)

survminer::ggsurvplot_combine(
  surv_comb, 
  data = df,
  combine = TRUE,
  censor = FALSE,
  legend = "none",
  palette = c("orange", "steelblue", "seagreen", "black"),
  linetype = c(rep("solid",3), "dashed"),
  )

这会产生下面的图表:

轴标题(“生存概率”)相对于轴标签被压扁。我尝试了多种方法来增加差距,包括 hjust/vjust 以及各种地方的

axis.title.x = element_text(margin = margin(t = 10, "mm"))
之类的东西,但似乎没有任何效果。如果我尝试将绘图分配给一个对象,然后添加 + theme(),我会收到 ggsurvplot 不支持这个的错误。谷歌搜索只返回有关 ggplot 的答案,而不是 ggsurvplot。请问有人知道如何给我的轴标题一点呼吸空间吗?谢谢!

r ggplot2 survival-analysis survival
1个回答
0
投票

您可以使用 ggplot 中的

labs
添加 y 轴和 x 轴标签,并添加
\n
以插入一个中断,这样可以添加一些空间:

library(survival)
library(survminer)
library(ggplot2)

survminer::ggsurvplot_combine(
  surv_comb, 
  data = df,
  combine = TRUE,
  censor = FALSE,
  legend = "none",
  palette = c("orange", "steelblue", "seagreen", "black"),
  linetype = c(rep("solid",3), "dashed"),
) + labs(y = "Survival probability \n", x = "\n Time")

创建于 2023-03-10 与 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.