是否可以在Survminer中自定义p值文本

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

我正在生成要在演示文稿中使用的生存曲线,理想情况下我想自定义 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)
r ggplot2 themes survminer
2个回答
2
投票

是的。

首先将您的绘图存储在

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) 坐标即可。根据您的喜好编辑或设计文本。


0
投票

简单地说:

ggsurvplot(fit, palette = c("#C83296", "#009EA0"), pval = "My custom p-value", legend = c(0.84, 0.8), legend.title = "", ggtheme = theme_kcl)

详情请查看https://github.com/kassambara/survminer/issues/189

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