我正在生成生存曲线,以便在演示文稿中使用,理想情况下,我希望自定义p值文本的颜色。这样做有可能吗?我已经用样本数据做了一个例子,向您展示我到目前为止所做的工作。剩下的就是#5A6469的p值文本的颜色了,但我已经尝试了几乎所有的选项,它仍然是绝对的黑色!谢谢你的帮助。
library(tidyverse)
library(survival)
library(survminer)
# theme using custom colour palette and with transparent background because the slides are grey
theme_kcl <- theme_classic() + theme(plot.title = element_text(colour = "#0A2D50", size = 16, hjust = 0.5), axis.title = element_text(colour = "#0A2D50", size = 14), axis.title.x = element_text(margin = margin(t = 10, r = 0, b = 0, l = 0)), axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)), axis.text = element_text(colour = "#5A6469", size = 12), legend.text = element_text(colour = "#5A6469", size = 12)) + theme(axis.ticks.x = element_line(colour = "#5A6469"), axis.ticks.y = element_line(colour = "#5A6469"), axis.line = element_line(colour = "#0A2D50")) + theme(panel.background = element_rect(fill = "transparent", colour = NA), plot.background = element_rect(fill = "transparent", colour = NA), legend.background = element_rect(fill = "transparent", colour = NA))
# Fit example data
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Draw survival curves
ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = TRUE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)发布于 2020-01-24 01:44:38
是。
首先将绘图存储在j中
j <- ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = FALSE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)我更改了pval=FALSE,因为您将要手动添加p值文本。
如果需要执行对数秩检验来估计p值,只需键入
survdiff(Surv(time, status) ~ sex, data = lung)然后
j$plot <- j$plot +
annotate("text", x = 10, y = 15, label = "P-value", cex=3.3, col="darkgrey", vjust=0, hjust = 1.1, fontface=2)
j只需更改(x,y)-coordinates即可。根据您的喜好编辑或设计文本。
https://stackoverflow.com/questions/59884112
复制相似问题