Search code examples
raxissurvival-analysisweibull

set x-axis limits in ggplot2 -> when adding another regression line, numbers on x-axis disappear


I want to plot a kaplan meier curve and overlay it with a Weibull regression line. Since the Weibull can make predictions exceeding the survival times of the data I would like to make the Weibull regression line 'longer'. My problem is: when I set my X-asis limits the numbering ends when the KM curve end (see curve below)

This is my code:

car2 <- car2[-c(34:39,41,43),]      # I only need this variables from the dataset
s1 <- with(car2,Surv(Time_OS_m,Event_OS))    #create survival object
fKM1 <- survfit(s1 ~ Eigenschap,data=car2)    #Kaplan meier curve for s1 
sWei1 <- survreg(s1 ~ as.factor(Eigenschap),dist='weibull',data=car2)   #Weibull regression line
summary(sWei1)

pred.I1 = predict(sWei1, newdata=list(Eigenschap="SA"),type="quantile",p=seq(.01,.99,by=.01))
pred.I2 = predict(sWei1, newdata=list(Eigenschap="I"),type="quantile",p=seq(.01,.99,by=.01))

df1 = data.frame(y=seq(.99,.01,by=-.01), Eigenschap1=pred.I1, Eigenschap2=pred.I2)
df_long1 = gather(df1, key= "Eigenschap", value="Time_OS_m", -y)  #Convert to long data format

p = ggsurvplot(fKM1, data = car2, risk.table = TRUE, legend.title="", 
               legend.labs = c("Infusion", "Screenfailure/\napheresis only"),
               title = "Overall Survival (with Weibull distribution)",
               pval = TRUE,
               pval.coord = c(0, 0.03),
               pval.size = 3.5,
               xlim = c(0,70))  #here i set the X axis limits 
p$plot = p$plot + geom_line(data=df_long1, aes(x=Time_OS_m, y=y, group=Eigenschap))
p

Above code gives this plot: enter image description here

Can someone help me get the x axis numbered all the way to the end, What am I doing wrong here?


Solution

  • This could be achieved via the argument break.x.by.

    Using the first example from survminer::ggsurvplot try this:

    library(survey)
    library(survminer)
    
    fit <- survfit(Surv(time, status) ~ sex, data = lung)
    
    # Basic survival curves
    ggsurvplot(fit, data = lung, xlim = c(0, 1500))
    

    ggsurvplot(fit, data = lung, xlim = c(0, 1500), break.x.by = 250)