Reputation: 21
How can I change the order in this plot based on the values of column?
Upvotes: 1
Views: 969
Reputation: 11649
This example should help you. You just need the reorder
Based on R documentation:
reorder is a generic function. The "default" method treats its first argument as a categorical variable, and reorders its levels based on the values of a second variable, usually numeric.
library(ggplot2)
dt<-data.frame("Name"=c("A","B","C","D","E"),value=sample(5))
ggplot(dt, aes( x= reorder(Name, value) , y= value))+
geom_col(stat='identity', aes(fill=Name), width=.5)
The result is:
Upvotes: 6