Last active
March 4, 2016 22:33
-
-
Save steveharoz/440466b4c650db7ad168 to your computer and use it in GitHub Desktop.
ordering in ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
data = data.frame( | |
a = rep(LETTERS[24:26], 3), | |
b = 1:9, | |
c = rep(LETTERS[1:3], each=3) | |
) | |
# uncomment to set facet order by refactoring the data | |
#data$a = factor(data$a, levels=c('Y', 'X', 'Z')) | |
ggplot(data, aes(x=c, y=b, fill=c)) + | |
geom_bar(stat='identity') + | |
# uncomment to set order of discrete axis | |
#scale_x_discrete(limits=c('C', 'A', 'B')) + | |
# uncomment to set order in legend | |
#scale_fill_discrete(breaks=c('B', 'C', 'A')) + | |
facet_grid(. ~ a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment