Using the code from here, I have realized something I do not understand:
library(ggplot2)
LoTRdata <- structure(list(Film = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("The Fellowship Of The Ring",
"The Return Of The King", "The Two Towers"), class = "factor"),
Race = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L,
3L, 3L, 1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Elf", "Hobbit",
"Man"), class = "factor"), Gender = structure(c(1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L
), .Label = c("Female", "Male"), class = "factor"), Words = c(1229L,
971L, 14L, 3644L, 0L, 1995L, 331L, 513L, 0L, 2463L, 401L,
3589L, 183L, 510L, 2L, 2673L, 268L, 2459L)), .Names = c("Film",
"Race", "Gender", "Words"), class = "data.frame", row.names = c(NA,
-18L))
p <- ggplot(LoTRdata, aes(x = Race, y = Words, fill = Film))
p + geom_bar(stat = "identity", position = "dodge") +
coord_flip() + guides(fill = guide_legend())
Why is the order of the bars reversed? And how can I change the order of the bars
I am aware that I could use guides(fill = guide_legend(reverse = TRUE))
but then the order of the bars and the legend are both reversed (the legend is not alphabetically ordered anymore).
In contrast to this question, where the order of each grouped bars is depending on the highest occurence, I just want to know how to reverse the order of each group (the same order it would be as if I wouldn't use coord_flip
).