I reduced the ntree down from 500 to 100 to reduce waiting time... I found I had to add a missing bracket from the end there.
also when you make imp , there is no rf to make it from, rather rf3.
The problem you had was the varimp result gives a named numeric vector, as_tibble default behaviour wont capture that as nicely as other more appropriate tooling, such as dplyr::enframe.
library(tidyverse)
library(caret)
library(ranger)
library(party)
rf3 <- cforest( score ~ ., data = readingSkills, control = cforest_unbiased(mtry = 2, ntree = 100))
imp <- rf3 %>%
varimp(conditional = TRUE) %>%
enframe() %>%
rename(Feature = name,
Importance = value)
ggplot(imp, aes(x = reorder(Feature, Importance), y = Importance)) +
geom_bar(stat = "identity", fill = "#53cfff", width = 0.65) +
coord_flip() +
theme_light(base_size = 20) +
theme(axis.title.x = element_text(size = 15, color = "black"),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 15, color = "black"),
axis.text.y = element_text(size = 15, color = "black"))