I have numeric data corresponding to subcategories and categories:
Category <- c("Cell", "Cell", "Nucleus", "Nucleus", "Metabolism", "Metabolism")
Subcategory <- c ("c","r","f","z","a","e")
Val <- c(1,5,34,89,23,12)
df <- data.frame(Category,Subcategory,Val)
I tried:
ggplot(df, aes(x=Subcategory, y=Val)) +
geom_bar(stat="identity", aes(fill=Category)) +
coord_flip() +
xlim(rev(levels(df$Subcategory)))
The problem is the order in xlim
:
xlim
always puts the letters in alphabetical array, begins with "a" if I use rev(...), or begins with "z" if: xlim(levels(...).
Is there any way to take the order that I have in the df?
I'd like that the order in x corresponds to the order of the categories, although this implies that the letters of the subcategories remain non-alphabetical.