Open ZihaoXingUP opened 3 years ago
Experiencing a similar issue trying to use par(mfrow=c(1,2))
library(survival)
library(survminer)
# example data frame
xx = data.frame(stim = c(2, 1:4),
sts = rep(1, 5))
# survfit
oo = survfit(Surv(time = stim, event = sts) ~ 1, data = xx)
par(mfrow=c(1,2))
# plot 1
plot(oo)
# ggsurvplot
ggsurvplot(fit = oo, xlim=c(-2, 5))
The ggsurvplot is produced as an separate figure without the original plot on the side.
Experiencing a similar issue trying to use par(mfrow=c(1,2))
library(survival) library(survminer) # example data frame xx = data.frame(stim = c(2, 1:4), sts = rep(1, 5)) # survfit oo = survfit(Surv(time = stim, event = sts) ~ 1, data = xx) par(mfrow=c(1,2)) # plot 1 plot(oo) # ggsurvplot ggsurvplot(fit = oo, xlim=c(-2, 5))
The ggsurvplot is produced as an separate figure without the original plot on the side.
i try your codes ,but it din't work
library(survival)
library(survminer)
# example data frame
xx = data.frame(stim = c(2, 1:4),
sts = rep(1, 5))
# survfit
oo = survfit(Surv(time = stim, event = sts) ~ 1, data = xx)
par(mfrow=c(1,2))
# plot 1
plot(oo)
# ggsurvplot
ggsurvplot(fit = oo, xlim=c(-2, 5))
thanks your advice. but ggsurvplot based on ggplot , not on the par plot system. so ,it can't draw multi plots on a picture when i try your codes.
if i don't use ggsurvplot, i do can draw multi plots on one figure.
library(survival)
library(survminer)
# example data frame
xx = data.frame(stim = c(2, 1:4),
sts = rep(1, 5))
par(mfrow=c(1,2))
oo = survfit(Surv(time = stim, event = sts) ~ 1, data = xx)
# plot a simple boxplot
plot(1:5,2:10)
#plot a survline plot
plot(oo)
This is the solution: plot1<–datos %>% ggsurvplot(fit1,data=.) plot1<–datos %>% ggsurvplot(fit2,data=.)
ggarrange(plotlist=list(plot1$plot,plot2$plot), labels = c("A", "B",), ncol = 1, nrow = 2)
This is the solution: plot1<–datos %>% ggsurvplot(fit1,data=.) plot1<–datos %>% ggsurvplot(fit2,data=.)
ggarrange(plotlist=list(plot1$plot,plot2$plot), labels = c("A", "B",), ncol = 1, nrow = 2)
Could you explain the code “plot1<–datos %>% ”? This does not work in my computer. Thank you.
This is the solution: plot1<–datos %>% ggsurvplot(fit1,data=.) plot1<–datos %>% ggsurvplot(fit2,data=.) ggarrange(plotlist=list(plot1$plot,plot2$plot), labels = c("A", "B",), ncol = 1, nrow = 2)
Could you explain the code “plot1<–datos %>% ”? This does not work in my computer. Thank you.
plot1<–datos %>% ggsurvplot(fit1,data=.)
is equivalent to: plot1<– ggsurvplot(fit1, data=datos)
where datos
is a data frame with survival information. Does that help to clarify?
helps clarifying but it still doesn't solve the issue in my case.
Many thanks,
Jenny
Late to the answer here, but the output from ggsurv contains the combine output including plot and data, which is why it throws an error with ggarrange.
The answer by @fufo64 is correct in that specifying the $plot from the ggsurvplot output in ggarrange works, but there's no need to add them as a list or include the pipe in the ggsurv call.
Reproducible example here:
require("survival")
require(ggpubr)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
a <- ggsurvplot(fit, data = lung)
b <- ggsurvplot(fit, data = lung, surv.median.line = "hv", palette = c("#E7B800", "#2E9FDF"))
ggarrange(a$plot,b$plot,ncol=2, widths=c(1,1), labels = c("a", "b"))
If you are using cowplot
, plot_grid(a$plot,b$plot)
also works
ggarrange(diff.exp.plot, ggsurvline.plot) Error: Cannot convert object of class ggsurvplotggsurvlist into a grob ,when i want to ggarrange a box plot on the left and ggsurvplot on the right