I'm plotting a survival curve with the survival
library, and I haven't found any way to change the breaks range.
For example:
library(survival)
temps <- c(5,15,25,30,18,16,38,40,40,40,40,40,40,40,40,40)
deces <- c(1,0,1,1,1,0,1,1,0,0,0,0,0,0,0,0)
plot(survfit(Surv(temps,deces)~1))
Gives us this plot:
If I want, I can change the range of the whole axis with xlim=c()
, the scale of abscissa numbers with xscale
.
But the x breaks ranges will always stay at every 5 or 10 units (10,20,30,40). It's impossible to change them to 12 for example, as I want (12, 24,36,...) because they should represent months.
Is this possible to change them? Or do I have to use the survminer
library?
To customized the axes, save the survfit
object and plot it with graphics parameter xaxt = "n"
, meaning, no x
axis. Then plot the x
axis with axis()
.
library(survival)
temps <- c(5,15,25,30,18,16,38,40,40,40,40,40,40,40,40,40)
deces <- c(1,0,1,1,1,0,1,1,0,0,0,0,0,0,0,0)
sv <- survfit(Surv(temps, deces) ~ 1)
plot(sv, xaxt = "n")
axis(1, at = seq(0, max(temps) + 12, by = 12))