0

I struggle with R ....How do I cut out the observations from 10- 25 years to make a Kaplan meier plot for up to 10 years:

what would I add to this line of code? Or would I Need to make separate groups for 0-1 year, 1-2 years and so on?

km.model <- survfit(Survival(Time, Diabetes) ~ Over40, type = "Kaplan-Meier")
plot(km.model, conf.int = F, lab = "Time(years)", lab = %Notdiabetic = S(t), main = "KM-Model")
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
Murphy
  • 9
  • 3
  • 2
    Since you're plotting a `survfit` object, you can find the relevant plotting help page at `?plot.survfit`. There you'll see the argument `xlim` to set the x-axis limits, so add `xlim = c(0, 10)` to your plot call (assuming it is in years... `xlim = c(0, 10 * 365)` if your data is in days...) – Gregor Thomas Dec 03 '20 at 15:18
  • Thanks Gregor- this was exactly what I was looking for :) – Murphy Dec 03 '20 at 23:20

1 Answers1

1

As with most base plotting functions, you can set the x-axis limits with xlim. See ?plot.survfit for more details.

plot(
  km.model,
  conf.int = F,
  lab = "Time(years)",
  lab = "%Notdiabetic = S(t)",
  main = "KM-Model", 
  xlim = c(0, 10)
)
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294