R语言绘制生存曲线图

R语言绘制生存曲线图,第1张

下图显示内置数据集colon,病人rx处理分为三组(下图第三列),对照组: Obs ,处理组一: Levamisole (Lev) ,处理组二: Levamisole + 5-fluorouracil (Lev+5FU)

# loads dplyr

library(dplyr)

# core survival analysisfunctions

library(survival)

# recommended forvisualizing survival curves

library(survminer)

#加载内置colon数据集

data(colon)

#list directory contents

ls(colon)

得到如下图:

#创建生存对象

fit <- survfit(Surv(time, status)~rx, data=colon)

#level()是为了看分组水平情况,以确定对照组,一般level()之后第一个为对照组

levels(colon$rx)

ggsurvplot(fit,risk.table=TRUE,#生存统计统计表

                  conf.int=TRUE,#添加置信区间带

                  palette = c("skyblue","green","red"),#颜色设置

                  pval=TRUE,#log-rank检验

                   pval.method=TRUE)#添加检验text

至于是treatment中的哪一组与Obs相比,显著性,差异性更大,需要查看 Lev 和 obs 对比的p值及HR,以及 (Lev+5FU) 和 Obs 对比的p值及HR,评价分组的治疗效果

#Cox Regression,评价rx分组后治疗效果

fit1<-coxph(Surv(time, status)~rx, data=colon)

fit1

ggsurvplot(

fit, #生存分析结果

data = NULL, #a dataset used to fit survival curves

fun = NULL, # 定义生存曲线转换的任意函数。 经常使用的转换可以用字符参数指定:“event”绘制累积事件(f(y) = 1-y),“cumhaz”绘制累积风险函数(f(y) = -log(y)),“pct”以百分比表示生存概率。

color = NULL, #曲线颜色

palette = NULL, #颜色调色板,可选调色板有 "grey","npg","aaas","lancet","jco", "ucscgb","uchicago","simpsons"和"rickandmorty".

linetype = 1, #线条形状,可以用数值型向量1,2表示,也可以用字符串向量c("solid", "dashed").

conf.int = FALSE, #是否画出置信区间

pval = FALSE, #是否显示P值

pval.method = FALSE, #是否添加计算P值得方法得文本,前提是pval = TRUE

test.for.trend = FALSE, #默认是F,如果TURE,返回trend Pvalues检验。 趋势检验旨在检测生存曲线的有序差异。 也就是说,至少对一个群体来说。 只有组数为>2时,才能进行趋势测试。

surv.median.line = "none", #画一条水平或者垂直得生存中位值线,允许的值有c("none", "hv", "h", "v"). v: 垂直vertical, h:水平horizontal.

risk.table = FALSE, #是否显示风险table。其他值有absolute" or "percentage",显示绝对数值/百分比;参数"abs_pct" ,百分比以及绝对数值都显示

cumevents = FALSE, # logical value specifying whether to show or not the table of the cumulative number of events.

cumcensor = FALSE, #logical value specifying whether to show or not the table of the cumulative number of censoring.

tables.height = 0.25, #设置table得高度,取值范围0-1

group.by = NULL, #包含分组变量名称得字符串向量。长度<=2

facet.by = NULL, #一个字符向量,包含将生存曲线分成多个面板的分组变量的名称。

add.all = FALSE, #一个逻辑值。 如果为TRUE,则在主图中添加合并患者(null model)的生存曲线。

combine = FALSE, # a logical value. If TRUE, combine a list survfit objects on the same plot.

ggtheme = theme_survminer(), #主题名称

tables.theme = ggtheme, #主题名称,默认是theme_survminer.

... #后面描述的参数和其他参数将被传递给ggplot2 geom_*()函数,如linetype, size, ii)或ggpar()函数来定制图形。 看到的细节部分

)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11680655.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存