R:ggsurvplot 彩色图例标签(文本)
R : ggsurvplot colored legend labels (text)
我正在使用 ggsurvplot 制作生存图,我唯一无法实现的是在我的图例上获得彩色标签:图例线根据地层着色,但不是相关标签。我该怎么做?
我现在有什么:
ggsurv <- ggsurvplot(
fit = fit,
palette = colors,
break.time.by = .5, xlab = "Years",
surv.scale = "percent",
ylab = "Transplant-free Survival",
censor.shape="|", censor.size = 2,
legend = c(.2,.3),
legend.labs = c("0 criterion", "1 criterion", "2 criteria", "3 criteria"),
legend.title = "",
font.legend = c(12, "plain"),
risk.table = T,
risk.table.title = "Number at risk by time",
risk.table.fontsize = 3,
risk.table.height = 0.3, surv.plot.height = 0.7,
title = "Transplant-free survival according to the number of\nnon-invasive low-risk criteria",
font.main = c(12, "bold"),
pval = T, pval.size = 4, pval.coord = c(2, .1),
)
ggsurv$table <- ggsurv$table + theme(plot.title = element_text(size = 12, hjust = -0.3))
ggsurv$plot <- ggsurv$plot + theme(plot.title = element_text(hjust = .5))
ggsurv
你有什么想法吗?谢谢 !
奥利维尔
您可以尝试使用 annotation
添加彩色文本项
ggsurv$plot <- ggsurv$plot + annotate("text", x = 0, y = 0.35,
label = "Text here", cex=5, vjust=0.5,
hjust = 0, fontface=2, col="red")
然后
> ggsurv
我正在使用 ggsurvplot 制作生存图,我唯一无法实现的是在我的图例上获得彩色标签:图例线根据地层着色,但不是相关标签。我该怎么做?
我现在有什么:
ggsurv <- ggsurvplot(
fit = fit,
palette = colors,
break.time.by = .5, xlab = "Years",
surv.scale = "percent",
ylab = "Transplant-free Survival",
censor.shape="|", censor.size = 2,
legend = c(.2,.3),
legend.labs = c("0 criterion", "1 criterion", "2 criteria", "3 criteria"),
legend.title = "",
font.legend = c(12, "plain"),
risk.table = T,
risk.table.title = "Number at risk by time",
risk.table.fontsize = 3,
risk.table.height = 0.3, surv.plot.height = 0.7,
title = "Transplant-free survival according to the number of\nnon-invasive low-risk criteria",
font.main = c(12, "bold"),
pval = T, pval.size = 4, pval.coord = c(2, .1),
)
ggsurv$table <- ggsurv$table + theme(plot.title = element_text(size = 12, hjust = -0.3))
ggsurv$plot <- ggsurv$plot + theme(plot.title = element_text(hjust = .5))
ggsurv
你有什么想法吗?谢谢 ! 奥利维尔
您可以尝试使用 annotation
ggsurv$plot <- ggsurv$plot + annotate("text", x = 0, y = 0.35,
label = "Text here", cex=5, vjust=0.5,
hjust = 0, fontface=2, col="red")
然后
> ggsurv