I want to generate a Kaplan-Meier plot from a dataset (data2), based on a original dataset from which two data points were removed (data1) to generate data2.
When I generate the KM plot for the original dataset (data1) the risk table displays properly (left plot), when using data2, no numbers at risk are shown at time 0 (right plot).
library(survival)
library(survminer)
data1 <- data.frame(
time_OS = c(11.47,6.57,3.57,21.73,10.67,12.40,7.17,16.37,15.43,4.93,13.43,
11.87,21.27,14.83,3.47,4.40,8.33,13.57,20.33,17.33,5.60,4.23,6.50,
4.63,13.73,14.03,12.93,1.13, 1.73),
cnsr_os_recode = c(2,2,2,1,2,2,2,2,1,2,2,1,1,1,2,2,1,1,1,1,1,1,1,2,2,1,1,2,2),
copies_gr_median = c(FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,FALSE,TRUE,TRUE,
FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,
TRUE,FALSE,TRUE,FALSE,FALSE,TRUE, TRUE, TRUE)
)
data2 <- data.frame(
time_OS = c(11.47,6.57,3.57,21.73,10.67,12.40,7.17,16.37,15.43,4.93,13.43,
11.87,21.27,14.83,3.47,4.40,8.33,13.57,20.33,17.33,5.60,4.23,6.50,
4.63,13.73,14.03,12.93),
cnsr_os_recode = c(2,2,2,1,2,2,2,2,1,2,2,1,1,1,2,2,1,1,1,1,1,1,1,2,2,1,1),
copies_gr_median = c(FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,FALSE,TRUE,TRUE,
FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,
TRUE,FALSE,TRUE,FALSE,FALSE,TRUE)
)
func1 <- Surv(time_OS, cnsr_os_recode) ~ copies_gr_median
sf1 <- survminer::surv_fit(func1, data = data1)
g1 <- survminer::ggsurvplot(
fit = sf1,
risk.table = TRUE,
conf.int = TRUE,
palette = 'jco',
ggtheme = theme_bw()
)
func2 <- Surv(time_OS, cnsr_os_recode) ~ copies_gr_median
sf2 <- survminer::surv_fit(func2, data = data2)
g2 <- survminer::ggsurvplot(
fit = sf2,
risk.table = TRUE,
conf.int = TRUE,
palette = 'jco',
ggtheme = theme_bw()
)
splots <- list()
splots[[1]] <- g1
splots[[2]] <- g2
# Arrange multiple ggsurvplots and print the output
arrange_ggsurvplots(splots, print = TRUE,
ncol = 2, nrow = 1, risk.table.height = 0.3)
I have tried googling and recoding the variables, but have not had any success.
That looks like a bug to me, which can be circumvented by adding the break.time.by
argument to ggsurvplot
.
g2 <- survminer::ggsurvplot(
fit = sf2,
risk.table = TRUE,
conf.int = TRUE,
break.time.by=5 # <---- HERE
)
g2