ModelOriented / survex

Explainable Machine Learning in Survival Analysis
https://modeloriented.github.io/survex
GNU General Public License v3.0
95 stars 10 forks source link

change the color of 'plot.aggregated_surv_shap' #92

Closed Dacy34 closed 6 months ago

Dacy34 commented 6 months ago

I really appreciate the survex package you've created! Its model interpretation feature is indeed powerful! I recently encountered an issue. I tried to change the colors corresponding to each variable in plot.aggregated_surv_shap by assigning values to 'colors', but it seems to have no effect. Additionally, only the second color in the provided color vector changes the color in the importance plot, while the colors of the variables in the SHAP plot on the right side never change. How can I assign a color to a variable?

library(survex)
library(survival)
library(ranger)

vet <- survival::veteran
cph <- coxph(Surv(time, status) ~ ., data = vet, x = TRUE, model = TRUE)
exp <- explain(cph, data = vet[, -c(3,4)], y = Surv(vet$time, vet$status))

shap <- model_survshap(exp, veteran[c(1:4, 17:20, 110:113, 126:129), -c(3,4)])
plot(shap, colors = c('#73BCD5','#FEE6B5','#F8AA59','#ABDCE0','#E86254','#528FAC'))

Rplot

krzyzinskim commented 6 months ago

Thanks for your kind words!

Actually, there was a bug in the code for this plot, but I've fixed it in commit 119dd8a. Now, the first color in the provided colors vector will be used for the left barplot, while the remaining colors will be used for the SurvSHAP(t) lines on the right (if there are enough colors).

So you can now install the development version of our package (see here), and then this code would work: plot(shap, colors = c(additional_color_for_bars, '#73BCD5','#FEE6B5','#F8AA59','#ABDCE0','#E86254','#528FAC')), where additional_color_for_bars is the hex code for the selected color.

Dacy34 commented 6 months ago

How wonderful it is! Thanks a bunch for your quick response and for taking the time to make those adjustments. I have try the newst plot. it so cool! Thanks again!