Kaplan-Meier Curves with R

While Excel (and similar spreadsheet programs) are powerful, they are not really suited for survival analysis. For example, graphing Kaplan-Meier curves with Excel is less than ideal. Survival analysis will often require a statistical software package, like  SAS, SPSS, STATA, XLSTAT, etc. R is a free alternative that is widely used by academics. Be warned, the learning curve for R is steep, but the references below should be helpful.

An R script entitled KM graphs.R is provided that will allow you to graph Kaplan-Meier curves using R. You will have to download and install R (and RStudio if you like). Professor Roger Peng, at Johns Hopkins University, has an entire online course introducing R on YouTube and Coursera. This YouTube video shows you how to install R on Windows; he also has a video to install R on a Mac. You will also need to format the survival data you want to graph in a .CSV file. The file should have three columns: time to event, event occurrence, and treatment. The event occurrence and treatment columns should contain either a 0 or 1 to indicate whether the event has occurred or whether an individual received treatment, respectively. An example file entitled data.CSV is provided.

Once you have installed R, download the data.CSV file to the working directory in R and run the KM graphs.R script. You can then replace the data in the .CSV file with the data you want to graph.


  1. UCLA Institute for Digital Research and Education.
  2. Use Software R to do Survival Analysis and Simulation.
  3. Survival Analysis in R (www.openintro.org).
Tagged , , ,

One thought on “Kaplan-Meier Curves with R

  1. […] Update: I realized that downloading from Scribd can be inconvenient, so I’ve included a link to the Excel file on Google Drive. For the more daring, try graphing Kaplan-Meier curves with R. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: