您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页【r<-高级|生信|方案】怎么用R画出好看的生存曲线

【r<-高级|生信|方案】怎么用R画出好看的生存曲线

来源:二三娱乐

几次寻求度娘无果,而且我认为这么想的绝对不仅仅只有我一个,肯定有什么大神受不了然后出手。所以选择用谷歌引擎搜英文的,看看有什么好用的包没。

长话短说(之前写的内容因为用的VPN,发布的时候简书出问题全没了~~),介绍找到的survminer包。

安装和加载

install.packages("survminer")
if(!require(devtools)) install.packages("devtools")devtools::install_github("kassambara/survminer", build_vignettes = FALSE)
library("survminer")

画生存曲线

构建生存模型

require("survival")
fit <- survfit(Surv(time, status) ~ sex, data = lung)

画基本图:

ggsurvplot(fit, data = lung)

自定义生存曲线

ggsurvplot( fit, 
data = lung, 
size = 1, # change line size 
palette = c("#E7B800", "#2E9FDF"),# custom color palettes 
conf.int = TRUE, # Add confidence interval 
pval = TRUE, # Add p-value 
risk.table = TRUE, # Add risk table 
risk.table.col = "strata",# Risk table color by groups 
legend.labs = c("Male", "Female"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups 
ggtheme = theme_bw() # Change ggplot2 theme)

是不是更美了??

看看更详细的参数列表:

ggsurv <- ggsurvplot( 
fit, # survfit object with calculated statistics. 
data = lung, # data used to fit survival curves. 
risk.table = TRUE, # show risk 
table. pval = TRUE, # show p-value of log-rank test. 
conf.int = TRUE, # show confidence intervals for  
                           # point estimates of survival 
curves. palette = c("#E7B800", "#2E9FDF"), 
xlim = c(0,500), # present narrower X axis, but not affect
                         # survival estimates. 
xlab = "Time in days", # customize X axis label. 
break.time.by = 100, # break X axis in time intervals by 500. 
ggtheme = theme_light(), # customize plot and risk table with a theme. 
risk.table.y.text.col = T,# colour risk table text annotations. 
risk.table.height = 0.25, # the height of the risk table 
risk.table.y.text = FALSE,# show bars instead of names in text annotations 
                                        # in legend of risk table. 
ncensor.plot = TRUE, # plot the number of censored subjects at time t 
ncensor.plot.height = 0.25, 
conf.int.style = "step", # customize style of confidence intervals 
surv.median.line = "hv", # add the median survival pointer. 
legend.labs = c("Male", "Female") # change legend labels. 
)
ggsurv

还可以调整图中的字体和颜色喔~


如果这有帮助到你,写博文的时候别忘记向我的专题投稿哈~

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务