0

I'd like to plot a KM curve, but have very few events in the data set.This gives for a strange plot and i am wondering if it is possible to set the limits on the y-axis, highlighting the differences better.

Here is the dummy data:

set.seed(132456)

'dummy survival data'
df<-data.frame(id=seq(1,1000,1), event=rep(0,1000),time=floor(runif(1000,7,10)),group=floor(runif(1000,0,2)))

'set events for a few random subjects'
'only within the first 100 to check results more easily'

id_list<-c(as.numeric(floor(runif(10,1,100))))
df$event[df$id %in% id_list]<-1

'set survival times for events'
t_list<-c(as.numeric(floor(runif(8,1,5))))
df2<-df[df$event==1,]
df2
df2$time<-t_list


'combine data'
df<-rbind(df,df2)
summary(df)

'Set up surfit '
require(survminer)
KM_fit<-survfit(Surv(time , event) ~ 1 + strata(group),data= df)
ggsurvplot(KM_fit,
           title="TEST",
           risk.table = TRUE)

Any tips are much appreciated!

Juan
  • 171
  • 1
  • 12
  • I get an error when I run this line of your code: `df2$time<-t_list`. Perhaps you could just make the toy data frame for your example and share it directly via `dput`? – ulfelder Jan 18 '20 at 12:37
  • Try again, please. Should work – Juan Jan 18 '20 at 12:45
  • 1
    If you look at the documentation for `ggsurvplot` ([here](http://127.0.0.1:22826/library/survminer/html/ggsurvplot.html)), you'll see that you can change the scale of the y-axis by adding `ylim = c({min}, {max})` to your call to that function, e.g., `ggsurvplot(KM_fit, title="TEST", risk.table = TRUE, ylim = c(0.95,1))`. A plot for a data set with so few events is not going to be very informative no matter what, but that will do what you ask. – ulfelder Jan 18 '20 at 12:47
  • Thanks. About the plot being informative, that is indeed an issue, but thats how the data looks like. So i dont know how else to deal with it – Juan Jan 18 '20 at 12:51
  • The statistical power of tests in survival analysis depends almost entirely on the number of events. – IRTFM Jan 20 '20 at 00:47
  • Yes thats what i feared. So then this is an example how not to. Thanks! – Juan Jan 21 '20 at 11:39

0 Answers0