Skip to content

stat_km and geom_km for Kaplan-Meier Survival curves #1080

@sachsmc

Description

@sachsmc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions