是否可以在 Survminer 中自定义 p 值文本
Is it possible to customise the p-value text in Survminer
我正在生成要在演示文稿中使用的生存曲线,理想情况下我想自定义 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)
是的。
首先将您的绘图存储在 j
中
j <- ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = FALSE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)
我更改了 pval=FALSE
因为您要手动添加 p 值文本。
如果您需要执行 af 对数秩检验来估计您的 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) 坐标即可。根据需要编辑或设计文本。
我正在生成要在演示文稿中使用的生存曲线,理想情况下我想自定义 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)
是的。
首先将您的绘图存储在 j
j <- ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = FALSE, legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)
我更改了 pval=FALSE
因为您要手动添加 p 值文本。
如果您需要执行 af 对数秩检验来估计您的 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) 坐标即可。根据需要编辑或设计文本。