Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Survival Plots with Survminer - Blank Plot

I'm currently having an issue with blank plots appearing in rmarkdown chunk outputs for survminer. Please see image below.

enter image description here

It makes output difficult as it includes a huge empty space while trying to author reports.

enter image description here

I've been investigating this issue and I've narrowed it down to having to do with this print 'newpage' argument -

enter image description here

My question is - can anybody explain what exactly is happening here? - why is there a 'blank' plot and how can I not have it show ? - what exactly is happening when I have newpage = F for the first plot and newpage = T for the second plot to not have the blank page show ? - is there any other method of NOT having the first blank plot show ?

Thank you!

EDIT:

Reproducible Example -

require(survminer)
require(survival)

Data <- data.frame(
X = sample(1:30),
Y = sample(c(1,0), 30, replace = TRUE),
Z = sample(c(1,0), 30, replace = TRUE)
)

ggsurvplot(
 survfit(Surv(Data$X, Data$Y) ~ Data$Z),
 risk.table = T,
 break.time.by = 12,
 risk.table.fontsize = 3,
 font.tickslab = 10,
 font.x = 11,
 xlab = 'Time (Months)',
 font.y = 11,
 font.main = 11,
 legend = c(0.8, .9),
 legend.title = '',
 risk.table.height = .20,
 risk.table.title = element_blank(),
 censor = F,
 pval = T,
 pval.coord = c(6, .00),
 pval.size = 4,
 surv.scale = 'percent',
 risk.table.y.text = F,
 palette = 'Set1'
)
like image 422
Michael Luu Avatar asked Feb 27 '17 06:02

Michael Luu


People also ask

How do you plot survival curves in R?

The R package survival fits and plots survival curves using R base graphs. There are also several R packages/functions for drawing survival curves using ggplot2 system: The default graph generated with the R package survival is ugly and it requires programming skills for drawing a nice looking survival curves.

What is survminer in R?

survminer: Survival Analysis and Visualization. The survminer R package provides functions for facilitating survival analysis and visualization. The main functions, in the package, are organized in different categories as follow.

Is there a cheatsheet for survminer verion?

We recently released the survminer verion 0.3, which includes many new features to help in visualizing and sumarizing survival analysis results. In this article, we present a cheatsheet for survminer, created by Przemysław Biecek, and provide an overview of main functions.

What does arrange_ggsurvplots do?

arrange_ggsurvplots (): Arranges multiple ggsurvplots on the same page. ggsurvevents (): Plots the distribution of event’s times. surv_summary (): Summary of a survival curve.


2 Answers

In order to print the survival plot with no leading blank plots, print just the plot object returned by ggsurvplot(). For example,

library(survival)
library(survminer)
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung)
print(p$plot)
like image 84
jdb Avatar answered Sep 23 '22 12:09

jdb


This seems to work for me :

plot.new() 
print(p,newpage = FALSE)

This will also work if the plot has the risk table. This solution is better than doing first plot(p$plot) and then plot(p$table) as suggested by others, because the table and plots remain nicely aligned.

like image 44
Mitch Avatar answered Sep 21 '22 12:09

Mitch