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

Facet survival curves into multiple panels #205

Closed
kassambara opened this issue Apr 28, 2017 · 4 comments
Closed

Facet survival curves into multiple panels #205

kassambara opened this issue Apr 28, 2017 · 4 comments

Comments

@kassambara
Copy link
Owner

No description provided.

@kassambara
Copy link
Owner Author

New option facet.by added now in ggsurvplot() to draw multi-panel survival curves of a data set grouped by one or two variables. Alias of the ggsurvplot_facet() function.

Load required packages

library(survival)
library(survminer)

Compute survival curves

fit1 <- survfit( Surv(time, status) ~ sex, data = colon )

fit2 <- survfit( Surv(time, status) ~ sex + rx, data = colon )

Facet by one grouping variables

Facet by the treatment assignment rx

# Faceting fit 1
ggsurvplot(fit1, colon, facet.by = "rx", 
              palette = "jco", pval = TRUE)

rplot11

# Faceting fit 2
ggsurvplot(fit2, colon, facet.by = "adhere", 
           palette = "jco", pval = TRUE)

rplot16

Facet by two grouping variables

ggsurvplot(fit1, colon, facet.by = c("rx", "adhere"),
           palette = "jco", pval = TRUE)

rplot17

@jiajiaybyb
Copy link

I realized ggsurvplot_facet does not plot the survival lines all the way to 100%, is there a solution for this? Ideally I would like to have facet panels, with corresponding p values and survival tables in the output. Any recommend method for this? Thanks a lot!

@Yatros
Copy link

Yatros commented Apr 11, 2019

Hello,

Is it possible to add capability to ggsurvplot_facet() so that it accepts as input not only survfit objects, but also a list of survfit objects?

ggsurvplot() accepts already survfit lists.

Thank you very much,

Best Regards,

@audyavar
Copy link

audyavar commented Aug 27, 2019

Thanks so much @kassambara for adding this functionality. I use it regularly. If possible, can you add functionality to loop thru multiple variables i.e. if I m interested in say 10 median-cut variables and generate ggsurvplots faceted by a clinical variable like age, sex.
for(i in cols){ # cols are 10 variables which are genes
fit <- surv_fit(os ~ get(i), data = su_df)
p <- ggsurvplot(fit, su_df, facet.by = "psa_bins",
palette = "jco", pval = TRUE)
print(p)
}
Error in grDevices::col2rgb(colour, TRUE) : invalid color name 'get(i)'
the facet option doesnt seem to like the get() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants