bgreenwell / pdp

A general framework for constructing partial dependence (i.e., marginal effect) plots from various types machine learning models in R.
http://bgreenwell.github.io/pdp
93 stars 12 forks source link

Options to modify palettes #116

Closed JeromeMathieuEcology closed 3 years ago

JeromeMathieuEcology commented 3 years ago

Hi, A small suggestion: to give the possibility to adjust the palette used for the pdps in partial(). For instance: direction, begin and end. Thks, Jérôme

bgreenwell commented 3 years ago

Hi @JeromeMathieuEcology, sorry for the long delay in response, but you can already do that. Here's a minimal example using both plotting functions:

library(pdp)
library(ggplot2)
library(ranger)

rfo <- ranger(cmedv ~ ., data = boston)

pd <- partial(rfo, pred.var = c("rm", "lstat"), chull = TRUE)

pal1 <- viridisLite::inferno(100, alpha = 1, begin = 0, end = 0.3)
pal2 <- viridisLite::inferno(100, alpha = 1, begin = 0.3, end = 0.9)

gridExtra::grid.arrange(
  plotPartial(pd, col.region = pal1),
  plotPartial(pd, col.region = pal2),
  autoplot(pd, palette = "inferno", begin = 0, end = 0.3),
  autoplot(pd, palette = "inferno", begin = 0.3, end = 0.9),
  nrow = 2
)

image