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))}}}####創(chuàng)建生存對象
fit1 <-survfit(Surv(PFS, status)~FIB1, data=df)
ggsurv1 <-ggsurvplot(fit1,risk.table=F,#生存統(tǒng)計統(tǒng)計表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,#生存統(tǒng)計統(tǒng)計表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)