R语言ggsurv生存曲线一页多图的实现

  • Problem
  • Solution

Problem

You want to put multiple graphs on one page.


Solution

The easy way is to use the multiplot function, defined at the bottom of this page. If it isn’t suitable for your needs, you can copy and modify it.

First, set up the plots and store them, but don’t render them yet. The details of these plots aren’t important; all you need to do is store the plot objects in variables.

multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {library(grid)# Make a list from the ... arguments and plotlistplots <- c(list(...), plotlist)numPlots = length(plots)# If layout is NULL, then use 'cols' to determine layoutif (is.null(layout)) {# Make the panel# ncol: Number of columns of plots# nrow: Number of rows needed, calculated from # of colslayout <- matrix(seq(1, cols * ceiling(numPlots/cols)),ncol = cols, nrow = ceiling(numPlots/cols))}if (numPlots==1) {print(plots[[1]])} else {# Set up the pagegrid.newpage()pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))# Make each plot, in the correct locationfor (i in 1:numPlots) {# Get the i,j matrix positions of the regions that contain this subplotmatchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,layout.pos.col = matchidx$col))}}
}####创建生存对象
fit1 <- survfit(Surv(PFS, status)~FIB1, data=df)
ggsurv1 <- ggsurvplot(fit1,risk.table=F,#生存统计统计表pval=TRUE,ggtheme = theme_bw(),ylab="PFS",legend=c(0.8,0.9),legend.title="",#log-rank检验pval.method=TRUE)#添加检验text                          ###FIB1
fit2 <- survfit(Surv(OS, status)~FIB1, data=df)
ggsurv2 <- ggsurvplot(fit2,risk.table=F,#生存统计统计表pval=TRUE,ggtheme = theme_bw(),ylab="OS",legend=c(0.8,0.9),legend.title="",#log-rank检验pval.method=TRUE)
ggsurv2
##
multiplot(ggsurv1, ggsurv2, cols=2)

结果如下:两张生存曲线图片组合在一起了

R语言ggsurv生存曲线一页多图的实现相关推荐

  1. R语言ggplot2可视化分组的重叠图实战:grouped overlay plot

    R语言ggplot2可视化分组的重叠图实战:grouped overlay plot 目录 R语言ggplot2可视化分组的重叠图实战:grouped overlay plot #仿真数据

  2. R语言ggplot2可视化:可视化华夫饼图(Waffle Chart) 、华夫饼图可以直观地显示完成度(百分比)或者部分占整体的比例、华夫饼图适合于同类型指标的比较(Waffle Chart)

    R语言ggplot2可视化:可视化华夫饼图(Waffle Chart) .华夫饼图可以直观地显示完成度(百分比)或者部分占整体的比例.华夫饼图适合于同类型指标的比较(Waffle Chart) 目录

  3. R语言ggplot2可视化:可视化斜率图、对比同一数据对象随着时间推移多个状态的差异(Slope Chart)、例如、对比不同癌症5年期、10年期、15年期存活率的差异

    R语言ggplot2可视化:可视化斜率图.对比同一数据对象随着时间推移多个状态的差异(Slope Chart).例如.对比不同癌症5年期.10年期.15年期存活率的差异 目录

  4. R语言ggplot2可视化:可视化箱图、在箱图中添加抖动数据点(Dot + Box Plot)、自定义抖动数据点的大小、颜色、数据点分布在箱图中间、添加主标题、副标题、题注信息

    R语言ggplot2可视化:可视化箱图.在箱图中添加抖动数据点(Dot + Box Plot).自定义抖动数据点的大小.颜色.数据点分布在箱图中间.添加主标题.副标题.题注信息 目录

  5. R语言plot函数散点图、密度图实战

    R语言plot函数散点图.密度图实战 目录 R语言plot函数散点图.密度图实战 #仿真数据 #散点图中添加回归线

  6. R语言ggplot2可视化:为箱图的均值进行连线、将多个分组的均值连接起来Joining means on a boxplot with a line

    R语言ggplot2可视化:为箱图的均值进行连线.将多个分组的均值连接起来Joining means on a boxplot with a line 目录

  7. R语言ggplot2可视化:组合箱图(boxplot)和直方图(histogram)输出组合可视化结果

    R语言ggplot2可视化:组合箱图(boxplot)和直方图(histogram)输出组合可视化结果 目录

  8. R语言ggplot2可视化绘制累积计数图(累加图,cumulative counts)

    R语言ggplot2可视化绘制累积计数图(累加图,cumulative counts) 目录 R语言ggplot2可视化绘制累积计数图(累加图,cumulative counts)

  9. R语言ggplot2可视化在分面图(facet_grid)的条形图上添加计数(count)或者百分比(percent)标签实战

    R语言ggplot2可视化在分面图(facet_grid)的条形图上添加计数(count)或者百分比(percent)标签实战 目录

最新文章

  1. C++ STL: 容器vector源码分析
  2. shell中各种括号的作用
  3. laravel使用redis做缓存的方法
  4. Unit05: window 常用子对象-2 、 event 对象 、 Cookie
  5. TypeScript入门教程 之 for ... of 与 for ... in
  6. python推荐_利用Python构建一个简单的推荐系统
  7. 西瓜书《机器学习》决策树IDW3, C4.5公式推导
  8. rest_framework之解析器、路由控制、分页
  9. 云原生技术学习路线图 初阶+中阶+高阶
  10. memcache、redis
  11. 决策树识别MNIST数据集
  12. 计算机毕业设计之java+springboot基于vue的4S店车辆管理系统
  13. 问题——nvm use 出现exit status 1:乱码
  14. 中级java面试问题大全及答案大全
  15. 手机影音第十六天,集成eventbus代替广播 ;在音乐播放页面中间部分显示歌词
  16. 技术干货|eBay对流量控制说“so easy”!
  17. vb.net机房收费系统——类的理解(sqlhelper)
  18. idea在plugins中搜不到插件MyBatisX
  19. input file限制上传文件类型 后缀名
  20. 时间序列预测--ARIMA、LSTM

热门文章

  1. KDEConnect非常便利,kde plasma+android绝配
  2. 田野调查手记·浮山摩崖石刻(六)
  3. 玩转PYthon,用Python绘制全球疫情变化地图(好东西,值得一看~~~)
  4. 基于Android的股票交易软件,基于Android的股票交易系统的融资融券交易子系统的设计与实现...
  5. linux hana 版本查询,通过hdblcm更新HANA组件版本
  6. Node.js + Socket.io 实现一对一即时聊天
  7. 计算一个球的体积的程序HTML,【编程1小时】球体表面积和体积计算
  8. 全国青少年软件编程等级考试--scratch-三级-真题-五彩糖葫芦
  9. php字体大小_PHP中改变网页文字大小代码
  10. 汇编语言中word ptr | byte ptr分别是什么意思