Kaplan-Meier Survival Plot – with at risk table

Credit for the bulk of this code is to Abhijit Dasgupta and the commenters on the original post here from earlier this year. I have made a few changes to the functionality of this which I think warrant sharing.

A brief intro, this function will use the output from a survival analysis fitted in R with ‘survfit’ from the ‘survival’ library, to plot a survival curve with the option to include a table with the numbers of those ‘at risk’ below the plot.

Continue reading

gridExtra – Multiple plots from ggplot2

Thanks to this great post http://www.imachordata.com/?p=730 we can now put multiple plots on a display with ggplot2. This provides somewhat similar functionality to ‘par(mfrow=c(x,y))’ which would allow multiple plots with the base plot function. gridExtra doesn’t have quite the same level of options as ‘par’, but the syntax is simple.

grid.arrange( graph1, graph2, ncol=2

Simple. ‘grid.table’ is worth checking out as well.

NOTE: Saving

I normally use ‘ggsave(…)’ to save my plots created with ggplot2. This (as yet) doesn’t work with using grid.arrange. A work around is to use a more tradition/base approach:

grid.arrange( graph1, graph2, ncol=2)


Package available here: http://cran.r-project.org/web/packages/gridExtra/