How do i sort the values

Hey guys, i want to sort the variable but i dont know how to do that.
This is my code:

imp_train_bc <- as.data.frame(fit_train_bc$variable.importance)
colnames(imp_train_bc) <- c("Importance")

ggplot(imp_train_bc) + geom_bar(aes(x = Importance, y = rownames(imp_train_bc)), stat = "identity", width = 0.05) + geom_point(aes(x=Importance, y= rownames(imp_train_bc)), col = "Orange")

And this is what the result looks like:

I can't work with your code since you haven't provided sample data so I'm going to give you an example with a built-in dataset.

library(tidyverse)

iris %>% 
    group_by(Species) %>% 
    summarise(Petal.Length = mean(Petal.Length)) %>% 
    ggplot(aes(x = Petal.Length, y = reorder(Species, Petal.Length))) +
    geom_col(width = 0.05) +
    geom_point(col = "Orange")

Created on 2020-04-30 by the reprex package (v0.3.0)

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.