I have a dataset with time, status ( 1=death, 0 = censored), treatement =1,2 .
I create my survival object km_2, I want to plot Kaplan-Meijer plot using autoplot(). I do not know what my mistake is but setting the attributes ( legendLabs for example ) do not make any change to the basic KM plot.
km_2 <- survfit(Surv(time, status)~treatment, data=prostate)
library(ggplot2)
library(ggfortify)
autoplot(km_2,
alpha=0.7, #transparency of CIs
shape= 10, #shape used to incdicaed censored obs
xlab= 'month', ylab='% survived',
title = 'KM- plot to compare tr1, tr 2',
legendLabs= c('tr1','tr2'),
pval=T,
plotTable= T
)
There are a few things to point out here. Firstly,
autoplotis a generic function, so the method used and the arguments it accepts depends on the type of object you are passing to it. In this case, you are passing asurvfitobject, and you will be able to see the correct parameters to use if you type?autoplot.survfitinto the console.From this you will see that there is no
legendLabsorplotTableoption, and that the alpha for the confidence intervals is controlled withconf.int.alpha =. Similarly, the censoring shape is controlled withcensor.shape.Another issue is that there doesn't seem to be a way to change the factor labels in the legend, but in this case it is easy enough to change them in the data when you create the
survfitobject.Lastly, it's a good idea to make a reproducible example if you want prompt and useful answers. It took a while to recreate a reasonable data structure to test and demonstrate this answer.
As an aside, you might get a result closer to your expectation using
survminer:Reproducible data