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

solution to long strata names in risk table legend #28

Closed
MarcinKosinski opened this Issue Mar 23, 2016 · 11 comments

Comments

Projects
None yet
3 participants
@MarcinKosinski
Contributor

MarcinKosinski commented Mar 23, 2016

If one considers this graph

library(RTCGA.mutations)
library(dplyr)
library(survminer)
mutationsTCGA(BRCA.mutations, OV.mutations) %>%
    filter(Hugo_Symbol == 'TP53') %>%
    filter(substr(bcr_patient_barcode, 14, 15) == "01") %>% # cancer tissue
    mutate(bcr_patient_barcode = substr(bcr_patient_barcode, 1, 12)) ->
    BRCA_OV.mutations

library(RTCGA.clinical)
survivalTCGA(
    BRCA.clinical,
    OV.clinical,
    extract.cols = "admin.disease_code"
    ) %>%
    dplyr::rename(disease = admin.disease_code) -> BRCA_OV.clinical

BRCA_OV.clinical %>%
    left_join(
        BRCA_OV.mutations,
        by = "bcr_patient_barcode"
        ) %>%
    mutate(TP53 = ifelse(!is.na(Variant_Classification), "Mut","WILDorNOINFO")) ->
    BRCA_OV.clinical_mutations

BRCA_OV.clinical_mutations %>%
    select(times, patient.vital_status, disease, TP53) -> BRCA_OV.2plot

kmTCGA(
    BRCA_OV.2plot,
    explanatory.names = c("TP53", "disease"),
    break.time.by = 400,
    xlim = c(0,2000)
    ) -> km_plot
print(km_plot)

rtcga km
produced by ggsurvplot function, then one can notices that sometimes survival ruves are not very transparent because of the long names of stratas in the legend of risk table.

Do you think it would be possible to have coloured squares instead of names in the labels of risk table? And then the names of stratas could be coloured in regular legend above the survival-plot where there is more place ?

The example solution could look like this (poorly I had only 1 colour :P). This way the more spaced is designed for survival plot

img_5632

@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Mar 25, 2016

Contributor

@kassambara Do you by chance have any suggestion :)?

Contributor

MarcinKosinski commented Mar 25, 2016

@kassambara Do you by chance have any suggestion :)?

@kassambara

This comment has been minimized.

Show comment
Hide comment
@kassambara

kassambara Mar 25, 2016

Owner

It should work now:-)!

Note that, in ggsurvplot(), long strata names problem is detected when nchar > 5. But, may be we can set this to ~10.

library("survminer")
require("survival")
fit2 <- survfit( Surv(time, status) ~ rx + adhere,
                data = colon )

ggsurvplot(fit2, pval = TRUE,
          break.time.by = 400,
          risk.table = TRUE,
          risk.table.col = "strata",
          risk.table.height = 0.5, # Useful when you have multiple groups
          palette = "Dark2", ggtheme = theme_bw())

rplot01

Owner

kassambara commented Mar 25, 2016

It should work now:-)!

Note that, in ggsurvplot(), long strata names problem is detected when nchar > 5. But, may be we can set this to ~10.

library("survminer")
require("survival")
fit2 <- survfit( Surv(time, status) ~ rx + adhere,
                data = colon )

ggsurvplot(fit2, pval = TRUE,
          break.time.by = 400,
          risk.table = TRUE,
          risk.table.col = "strata",
          risk.table.height = 0.5, # Useful when you have multiple groups
          palette = "Dark2", ggtheme = theme_bw())

rplot01

@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Mar 25, 2016

Contributor

Amazing!
Survival plots have never been so informative and well organized :)
Thank you!

Contributor

MarcinKosinski commented Mar 25, 2016

Amazing!
Survival plots have never been so informative and well organized :)
Thank you!

@kassambara

This comment has been minimized.

Show comment
Hide comment
@kassambara

kassambara Mar 25, 2016

Owner

Thank you for this sweet comment:-)!
Best,
AK

Owner

kassambara commented Mar 25, 2016

Thank you for this sweet comment:-)!
Best,
AK

@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Mar 26, 2016

Contributor

Survival plots have never been so informative and well organized like a title for a good blog post for r-bloggers about new feature :)

long strata names problem is detected when nchar > 5. But, may be we can set this to ~10.

Does it mean it is being made automatically without user knowledge? Maybe it could be additional parameter: trim.strata.names = TRUE set to TRUE by defalut?

Contributor

MarcinKosinski commented Mar 26, 2016

Survival plots have never been so informative and well organized like a title for a good blog post for r-bloggers about new feature :)

long strata names problem is detected when nchar > 5. But, may be we can set this to ~10.

Does it mean it is being made automatically without user knowledge? Maybe it could be additional parameter: trim.strata.names = TRUE set to TRUE by defalut?

@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Mar 28, 2016

Contributor

@kassambara thanks for last commit :) What do you think about #28 (comment) ?

Contributor

MarcinKosinski commented Mar 28, 2016

@kassambara thanks for last commit :) What do you think about #28 (comment) ?

@kassambara

This comment has been minimized.

Show comment
Hide comment
@kassambara

kassambara Mar 28, 2016

Owner

That's a good suggestion @MarcinKosinski!

Now, a new logical argument added in ggsurvplot: risk.table.y.text. Default is TRUE. If FALSE, risk table y axis tick labels will be hidden.

library(survival)
library(survminer)

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

#1. Default plot
ggsurvplot(fit2, pval = TRUE,
          risk.table = TRUE,
          risk.table.height = 0.5)

# 2. Hide risk table y axis texts
ggsurvplot(fit2, pval = TRUE,
          risk.table = TRUE,
          risk.table.height = 0.5,
          risk.table.y.text = FALSE)
  1. Default plot:

rplot06

  1. Hide risk table y axis texts
    rplot07
Owner

kassambara commented Mar 28, 2016

That's a good suggestion @MarcinKosinski!

Now, a new logical argument added in ggsurvplot: risk.table.y.text. Default is TRUE. If FALSE, risk table y axis tick labels will be hidden.

library(survival)
library(survminer)

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

#1. Default plot
ggsurvplot(fit2, pval = TRUE,
          risk.table = TRUE,
          risk.table.height = 0.5)

# 2. Hide risk table y axis texts
ggsurvplot(fit2, pval = TRUE,
          risk.table = TRUE,
          risk.table.height = 0.5,
          risk.table.y.text = FALSE)
  1. Default plot:

rplot06

  1. Hide risk table y axis texts
    rplot07
@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Mar 28, 2016

Contributor

Great. So we can close this issue :) You can Update NEWS with new parameter and You should really think about new post on R-bloggers about new functionalities in ggsurvplot :)

Contributor

MarcinKosinski commented Mar 28, 2016

Great. So we can close this issue :) You can Update NEWS with new parameter and You should really think about new post on R-bloggers about new functionalities in ggsurvplot :)

@kassambara

This comment has been minimized.

Show comment
Hide comment
@kassambara

kassambara Mar 28, 2016

Owner

NEWS updated! a new blog post and new CRAN version will be soon released:-)!

Owner

kassambara commented Mar 28, 2016

NEWS updated! a new blog post and new CRAN version will be soon released:-)!

@shamav523

This comment has been minimized.

Show comment
Hide comment
@shamav523

shamav523 Aug 31, 2017

This is a fantastic package and I use it all the time! I just ran into an issue though. Could there be an option to use numbers instead of the tick marks? The tick marks rely on color to tell curves apart and I need to generate a black and white figure. Another option could be to be able to create a separate legend for the risk table that can utilize abbreviated terms while the full terms are present in the plot legend. Thank you!

shamav523 commented Aug 31, 2017

This is a fantastic package and I use it all the time! I just ran into an issue though. Could there be an option to use numbers instead of the tick marks? The tick marks rely on color to tell curves apart and I need to generate a black and white figure. Another option could be to be able to create a separate legend for the risk table that can utilize abbreviated terms while the full terms are present in the plot legend. Thank you!

@MarcinKosinski

This comment has been minimized.

Show comment
Hide comment
@MarcinKosinski

MarcinKosinski Sep 1, 2017

Contributor
Contributor

MarcinKosinski commented Sep 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment