Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upLost ability to assign same color for same group accross facets #185
Comments
|
Thank you for pointing this out. Fixed now. Observation: you're using a hack to color curves by molecular_group accross facets. In order order to have the same color in all facets, you duplicated the levels of legend labels and color palettes. This is not recommended, because doing so, you'll always have the following warning:
suggestion: By default, survival curves are colored by strata using the argument This has been now clarified in the documentation of
Install the latest version as follow: if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer", build_vignettes = FALSE)Then, try this: library(tidyverse)
library(survminer)
library(survival)
myeloma<-myeloma
myeloma<-myeloma%>%mutate(type=sample(c(1,2), size=nrow(myeloma), replace=TRUE))
modelfit<-survfit(Surv(time, event)~molecular_group+type, data=myeloma)
# To visualize, use this
ggsurvplot(modelfit, data = myeloma,
legend.title = "Type",
color = "molecular_group",
palette = c("#F8766D","#E38900","#C49A00","#99A800","#53B400","#00BC56","#00C094")
) %>%
.$plot+facet_wrap(~type)
# Or this
ggsurvplot(modelfit, data = myeloma,
legend.title = "Type",
color = "molecular_group",
palette = "jco") %>%
.$plot+facet_wrap(~type)Please, let us know if it works for you so that we can close the issue |
|
@Eliford did this work? |
|
@kassambara . |
|
Oh, great! So we can close this issue. |

Expected behavior
In the previous version of survminer, the code below would give a plot with only 7 colors each for a molecular group. I liked it because the a molecular group had a same color across facets. It was then easy to compare survival curves across facets.
Actual behavior
With the current version the above code gives the error below
Steps to reproduce the problem
The dataset above comes with the survminer package. The code above shows how I was able to reproduce the problem that I observed with my data.
session_info()