Kaplan-Meier plots using ggplots2 (updated)

About 3 years ago I published some code on this blog to draw a Kaplan-Meier plot using ggplot2. Since then, ggplot2 has been updated (from 0.8.9 to and has changed syntactically. Since that post, I have also become comfortable with Git and Github. I have updated the code, edited it for a small error, and published it in a Gist. This gist has two functions, ggkm (basic Kaplan-Meier plot) and ggkmTable (enhanced Kaplan-Meier plot with table showing numbers at risk at various times).

This gist is published here. If you find errors or want to enhance these functions, please fork, update and send me a link to your fork in the comments. I’ll pull and merge them. Unfortunately Github doesn’t allow pull requests directly for gists (see here for the StackOverflow answer I’m basing this on).

If you want to go back to the original post, you can read it here.



  1. Hi there,
    Thank you so much for this code. It’s just what I was looking for.
    In order to make it work, I have had to change theme_text by element_text.

  2. Your ggkm() plot function is beautiful. However, the ggkmTable() function gives the following error:

    Error: theme_text is deprecated. Use ‘element_text’ instead. (Defunct; last used in version 0.9.1)

    Is there any chance you might update ggkmTable() to run under the most recent version of ggplot (I think it is 1.0.2)? I’m not smart enough to figure out how to fix it myself, nor how to go back to an older version of ggplot2. Many of us would surely love to use the ggkmTable() function for plotting full K-M graphs.


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