一般画森林图的forestplot包需要大家把格式整理成其需要的“标准格式”,笔者最早学习绘制森林图的时候也是利用的forestplot包,每次都需要把计算出来的数据进行“二次整理”,有点浪费时间,前段时间学习surminer包的时候发现其中有个ggforest函数,可以直接应用数据集和构建的cox回归方程绘制森林图,非常方便
以下为主要参数用法

实战代码
library(survival)
library(survminer)
library(tidyverse)
library(eoffice)
rm(list = ls())#清空列表
options(stringsAsFactors = F)#设定全局变量
构建回归方程
model <- coxph( Surv(time, status) ~ sex + rx + adhere,
data = colon )
绘制简单森林图(建议初学者所有形式参数都不要省略)
ggforest(model = model,#cox回归方程
data = colon,#数据集
main = "简单森林图")#标题

可以看到,其把sex当做了数值向量,下部对需要的分类变量因子化并美化图
#利用within函数因子化,直接利用factor也可以
colon <- within(colon, {
sex <- factor(sex, labels = c("female", "male"))
differ <- factor(differ, labels = c("well", "moderate", "poor"))
extent <- factor(extent, labels = c("submuc.", "muscle", "serosa", "contig."))
})
#以下构建回归方程
bigmodel <-
coxph(Surv(time, status) ~ sex + rx + adhere + differ + extent + node4,
data = colon )
#以下绘制森林图
p<- ggforest(bigmodel,colon)
print(p)

导出为pptx格式继续编辑
topptx(figure = p,filename = "森林图.pptx")


其实还还以继续美化哈
网友评论