Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stat_km and geom_km for Kaplan-Meier Survival curves #1080

Closed
sachsmc opened this Issue Apr 2, 2015 · 8 comments

Comments

Projects
None yet
5 participants
@sachsmc
Copy link

sachsmc commented Apr 2, 2015

People occasionally ask about plotting survival curves with ggplot2. While it is possible, see here for some examples, it's not done in the "ggplot way" and people often revert to the base plot because it's so much easier (but not nearly as powerful).

I've worked a bit on adding a stat and geom for computing and plotting survival curves here. I view it as along the same lines as stat_ecdf but for censored data. Before submitting a pull request I wanted to ask if this would be suitable for inclusion in ggplot2, or if it would be better as a standalone package?

Here's an example code and plot:

df <- survival::lung
ggplot(df, aes(x = time, status = status, color = factor(sex))) + geom_km()

image

@sachsmc sachsmc referenced this issue Jun 4, 2015

Closed

Feature/kmcurve #1114

@MarcinKosinski

This comment has been minimized.

Copy link

MarcinKosinski commented Jun 4, 2015

It looks like autoplot function from package survMisc produces KM curves for survfit object in a ggplot-way. It also produces a table with risk set size dependency over time.
http://www.inside-r.org/packages/cran/survMisc/docs/autoplot

library(survMisc)
data(kidney, package="KMsurv")
s1 <- survfit(Surv(time=time, event=delta) ~ type, data=kidney)
autoplot(s1)
autoplot(s1, CI=TRUE, pval=TRUE, plotTable=TRUE, divideTime=5,
 legendLabs=c("surgical", "percutaneous"),
 title="Time to infection following catheter placement \n
   by type of catheter, for dialysis patients")
s1 <- survfit(Surv(time=time, event=delta) ~ 1, data=kidney)
autoplot(s1)
data(rectum.dat, package="km.ci")
s1 <- survfit(Surv(time, status) ~ 1, data=rectum.dat)
### change confidence intervals to log Equal-Precision confidence bands
km.ci::km.ci(s1, method="logep")
autoplot(s1, bands=TRUE)
@sachsmc

This comment has been minimized.

Copy link
Author

sachsmc commented Jun 5, 2015

@MarcinKosinski Thanks for pointing that out, I was not aware of that function. While this autoplot does use ggplot2 to create a survival plot, I don't agree that it is done in the "ggplot way". I.e., there is no support for faceting, scale transformations, or even themes. Furthermore, it ignores the key concepts of the grammar of graphics, such as aesthetic mappings, layers, statistical transformations, and so on.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Jun 10, 2015

I'd rather it go in a separate package - have you considered adding the data related parts to broom?

@hadley hadley closed this Jun 10, 2015

@fpbarthel

This comment has been minimized.

Copy link

fpbarthel commented Feb 18, 2016

I'm very much interested in these functions, have been looking for survival functionality for ggplot forever. Found some solutions but none have been very satisfactory. How can I access these functions?

@sachsmc

This comment has been minimized.

Copy link
Author

sachsmc commented Feb 18, 2016

@fpbarthel They're available at my repo here, still under development and not on CRAN yet.

@fpbarthel

This comment has been minimized.

Copy link

fpbarthel commented Feb 18, 2016

Thanks

@MarcinKosinski

This comment has been minimized.

Copy link

MarcinKosinski commented Feb 18, 2016

Have a look at 'survminer' package :) available at CrAN and github

Marcin Kosinski

Dnia 18.02.2016 o godz. 18:18 fpbarthel notifications@github.com napisał(a):

I'm very much interested in these functions, have been looking for survival functionality for ggplot forever. Found some solutions but none have been very satisfactory. How can I access these functions?


Reply to this email directly or view it on GitHub.

@srw6v

This comment has been minimized.

Copy link

srw6v commented Apr 4, 2016

@MarcinKosinski great package. Much more flexible than autoplot.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.