Open bipoff opened 3 years ago
The ggsave
option does not work anymore for me either. This may be an R 4.1 issue, but I have not investigated. In the meantime, you can try an alternate approach:
pdf("survplot.pdf")
print(surv_plot, newpage = FALSE)
dev.off()
I have encountered the same problem with ggsave in R 4.1. The alternate approach proposed by igordot worked for me. Thanks!
The
ggsave
option does not work anymore for me either. This may be an R 4.1 issue, but I have not investigated. In the meantime, you can try an alternate approach:pdf("survplot.pdf") print(surv_plot, newpage = FALSE) dev.off()
This works well, thanks.
I encounter the same issue that the ggsave doesn't work with ggsurvplot object any more. ggsave() can designate the width and length in mm, which is convenient for different requirements from different journals. So my workaround is this:
pdf(file = "survplot.pdf",
width = measurements::conv_unit(x = 183, from = "mm", to = "inch"),
height = measurements::conv_unit(x = 183, from = "mm", to = "inch"))
print(a_ggsurvplot_object, newpage = FALSE)
dev.off()
Anyway, I hope the developers can fix this bug with ggsave()
It seems that there is a plot
member in the ggsurvplot
object that we can use.
Therefore, this works for me:
ggsave("plot.png", print(a_ggsurvplot_object$plot), width=17, height=10, units="cm")
Of course, this is only a workaround, as this will probably not take the table into account.
You can try saving plot member and table member separately, and then remerging by cowplot package or patchwork package
p <- ggsurvplot(fit, data = lung)
p1 = p$plot
p2 = p$table
plotp = cowplot::plot_grid(p1,p2,align = "v",ncol =1,rel_heights = c(4,1))
ggsave(filename = "test.pdf", plot = plotp, device = "pdf")
Another workaround is to use ggsave("plot.pdf", survminer:::.buildggsurvplot(my_plot))
. I think it's worth considering making survminer:::.buildggsurvplot(my_plot)
an exported function since it is useful at times to be able to get the resultant gtable for downstream manipulation. I've therefore created issue #569 for this.
Thanks, it works for me.
You can try saving plot member and table member separately, and then remerging by cowplot package or patchwork package
p <- ggsurvplot(fit, data = lung) p1 = p$plot p2 = p$table plotp = cowplot::plot_grid(p1,p2,align = "v",ncol =1,rel_heights = c(4,1)) ggsave(filename = "test.pdf", plot = plotp, device = "pdf")
This might be the best solution so far!
Hi,
first of all, thank you very much for providing us with this invaluable package! I used it for two years now, but now there is below issue coming up.
Thanks a lot!
Expected behavior
ggsave should be ble to save ggsurvplots with risk tables. I use
plot = print(plot, newpage = F)
. Still it does not work as it used to work ealier.Actual behavior
the saved pdf is empty
Steps to reproduce the problem
library(survival) library(survminer) library(tidyverse) library(Cairo) fit<- survfit(Surv(time, status) ~ sex, data = lung) plot <- ggsurvplot(fit, data = lung, risk.table = T) plot ggsave("plot.pdf", plot = print(plot, newpage = F), device = cairo_pdf)
session_info()