Changing x-axis lable and x-axis interval in a ggsurvplot

I would like to make a gg survplot with ggplot in R, I succeeded to make such a survplot but I am wondering how to change the x-axis title and x-axis interval.

Here is the statement I used in R:

sfit <- survfit(Surv(time_until_quit, quits_within_given_interval)~set1, data=DAT1)

ggsurvplot(sfit, conf.int=TRUE, pval=TRUE, risk.table=TRUE,
legend.labs=c("Set1", "Set2"), legend.title="Sets",
title="Curve with information about quitting")

I want to place ‘Time until quitting’ on the x-axis and have a difference of 50 between the intervals.

Thanks for your help in advance!

Looking at the documentation, it appears adding arguments for xlab = and break.x.by = might do it.

ggsurvplot(sfit, 
           conf.int=TRUE, 
           pval=TRUE, 
           risk.table=TRUE,
           legend.labs=c("Set1", "Set2"), 
           legend.title="Sets",
           title="Curve with information about quitting",
           xlab = 'Time until quitting', # updated
           break.x.by = 50 # updated
           )

Thanks, this works! :slight_smile:

1 Like

Do you maybe also know how to change the color of my ggsurvplot? It does not work when I add scale_fill_brewer(palette = "Blues")

I would like to have a ggsurvplot with a gradient colour scale :slight_smile:

You can create a palette of your own and add it using the palette = argument. In the example below, mypalette is a vector of the nine colors in RColorBrewer's "Blues" palette. Then, specify which shades you want in the function argument. In this case, I chose shades 6 and 8. If not specified, the first two are chosen.

mypalette = RColorBrewer::brewer.pal(n = 9, name = 'Blues')
  
ggsurvplot(sfit, 
           conf.int=TRUE, 
           pval=TRUE, 
           risk.table=TRUE,
           legend.labs=c("Set1", "Set2"), 
           legend.title="Sets",
           title="Curve with information about quitting",
           xlab = 'Time until quitting',
           break.x.by = 50,
           palette = mypalette[c(6,8)]
           )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.