# Making a cumulative incidence plot in R

## Background

I have a survival object in R called km.

> km
Call: survfit(formula = Surv(Surv_day, Survive) ~ 1, data = study_data)

records   n.max n.start  events  median 0.95LCL 0.95UCL
440     440     440      88    3964    3595      NA

> summary(km)
Call: survfit(formula = Surv(Surv_day, Survive) ~ 1, data = study_data)

time n.risk n.event survival std.err lower 95% CI upper 95% CI
69    432       1    0.998 0.00231        0.993        1.000
91    431       1    0.995 0.00327        0.989        1.000
104    430       1    0.993 0.00400        0.985        1.000
128    428       1    0.991 0.00461        0.982        1.000
137    427       1    0.988 0.00515        0.978        0.999
141    426       1    0.986 0.00564        0.975        0.997
216    423       1    0.984 0.00609        0.972        0.996
223    422       1    0.981 0.00650        0.969        0.994
227    421       1    0.979 0.00689        0.966        0.993
.... And so forth....


I know that I can easily make a beautiful Kaplan-Meier curve by typing:

> plot(km) ## Question

How can I instead turn these data into a cumulative incidence curve, similar to the example shown below, but also with confidence intervals? • So you want to plot $1-\hat S(t)$ instead of $\hat S(t)$ with c.i. but without censoring marks? (By $\hat S$ I mean the Kaplan-Meier estimate.) – Michael M Dec 29 '13 at 21:00
• Yes that's right. With or without censoring marks would be a nice option. – Alexander Dec 30 '13 at 3:59
• Even easier is to use the predefined function ("event") of plot.survfit: plot(km, fun="event") – Linda Hartman Oct 5 '17 at 9:03

## 1 Answer

This is a question about R programming, not about statistics. Thus, it would be more suited for our programming gurus on https://stackoverflow.com/. Nevertheless, here a quick answer:

Typing

plot(km, fun = function(x) 1-x)


gives you the desired result.