> ggplot(EDAfilter, aes(x = EDAfilter$MCI, fill=as.factor(EDAfilter$MCI))) +
+
+ geom_bar(width=0.8, stat="count") + theme(legend.position="none") + coord_flip() +
+
+ ggtitle("Crime Records by Major Categories")
This was my code to understand the distribution of counts by categories. I want to reorder this by descending order i.e. top category for counts to the lowest. Below is the plot I got. Let me know how to reorder this. I tried using reorder but failing.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
Thank you Andre. I shall keep this in mind for future posts. I found a work around for this using the dplyr package. Many thanks for your support. I shall come with more questions as I work on this project.
I think it's more convenient to count MCI yourself beforehand and then use geom_col() for your purposes. Reordering is done by fct_reorder
library(tidyverse)
EDAfilter %>%
count(MCI) %>%
ggplot(aes(x = fct_reorder(factor(MCI), n), y = n, fill = factor(MCI))) +
geom_col() +
theme(legend.position="none") +
coord_flip() +
ggtitle("Crime Records by Major Categories")