Skip to content
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

Barplot in palce of point pdp plot for categorical variables using autoplot function #132

Open
bappa10085 opened this issue Jul 24, 2023 · 1 comment

Comments

@bappa10085
Copy link

I think it is better to use barplot in palce of point pdp plot for categorical variables using autoplot function as suggested here. I am rpoviding a minimal reproduicible example here

library(pdp)

# dummy data
categorical <- c('A', 'A', 'A', 'A', 'B', 'B', 'B', 'B')
numerical <- c(1, 2, 3, 4, 1, 2, 3, 4)
target <- c(100, 200, 300, 400, 500, 600, 700, 800)
data <- data.frame(categorical, numerical, target)
data$categorical <- factor(data$categorical)

set.seed(101)  # for reproducibility
mod.rf <- randomForest(target ~ ., data = data)

cat.pdp <- partial(mod.rf, pred.var = c("categorical"))

autoplot(cat.pdp, contour = TRUE) 

image

Then I have tried the following code to generate barplot

autoplot(cat.pdp, contour = TRUE) +
  geom_col()

image

As we can see, the points are also plotted and the y-axis limit is starting from 0 unlike the point plot where y-axis limits are optimised according to the data.

It would be better if the point plot is repalced by barplot.

@bgreenwell
Copy link
Owner

Thanks @bappa10085, I’ll plan to add geom and aes arguments to make it more flexible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants