Home > Software design >  Having combined sv_dependence shapviz plots with feature value color bar displayed once
Having combined sv_dependence shapviz plots with feature value color bar displayed once

Time:12-13

I'm trying to arrange three sv_dependence() plots from shpaviz in a single graph with grid.arrange(). I would like the feature value color scale to appear just once. Here is a reproducible code, with the result I obtained so far:

library(shapviz)
library(ggplot2)
library(gridExtra)

set.seed(1)

X_train <- data.matrix(`colnames<-`(replicate(26, rnorm(100)), LETTERS))
dtrain <- xgboost::xgb.DMatrix(X_train, label = rnorm(100))
fit <- xgboost::xgb.train(data = dtrain, nrounds = 50)
shp <- shapviz(fit, X_pred = X_train)

p_a <- sv_importance(shp, kind = "beeswarm", show_numbers = TRUE, max_display = 15, color_bar_title=NULL)
p_b <- sv_importance(shp, kind = "beeswarm", show_numbers = TRUE, max_display = 15, color_bar_title=NULL)
p_c <- sv_importance(shp, kind = "beeswarm", show_numbers = TRUE, max_display = 15)
grid.arrange(p_a,p_b,p_c,nrow=1)

enter image description here

How can I make the third graph the same dimension of the other two while having the feature value color bar displayed?

CodePudding user response:

One option would be to switch to patchwork to glue your plots together.

library(patchwork)

p_a   p_b   p_c

enter image description here

  • Related