5130/changing-the-order-of-bars-in-a-bar-plot-ggplot2-r
I am working with the 'mtcars' dataset and have made this bar-plot with ggplot2:
I would want to arrange the bars in ascending order of count. i.e this needs to be the order of the bars: (6,8,3,1,2,4).
Is there a way to modify it?
You can use the scale_x_discrete() function with the parameter 'limits' to reorder the bars:
ggplot(data = mtcars,aes(x=factor(carb)))+geom_bar()+scale_x_discrete(limits=c(6,8,3,1,2,4))
The above command will give you the desired result:
@prardhana, Use scale_fill/color/size_discrete/contin....(labels = c()). compare both to see ...READ MORE
The key to ordering is to set ...READ MORE
R provides 3 basic indexing operators. Refer ...READ MORE
The function match works on vectors : x <- sample(1:10) x # ...READ MORE
By Using gridExtra library we can easily ...READ MORE
You can use the theme layer to ...READ MORE
The below command will give you the ...READ MORE
You just have to add 'outlier.shape=NA' inside ...READ MORE
Load the 'scales' package first, which gives ...READ MORE
Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.