Last active
August 29, 2015 14:26
-
-
Save jeffreyhanson/4f111566a535e7edb36f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# deps | |
library(magrittr) | |
library(dplyr) | |
library(ggplot2) | |
library(gridExtra) | |
# load data | |
data(iris) | |
# add in factor versions of the columns | |
# Species is alphabetically ordered | |
# Species2 is randomly ordered | |
iris %>% mutate( | |
Species=factor(Species), | |
Species2=factor(Species, levels=c("virginica", "setosa", "versicolor")) | |
) %>% group_by( | |
Species, | |
Species2 | |
) %>% summarise( | |
Sepal.Length=mean(Sepal.Length) | |
) -> meanDF | |
# make panels | |
p1=ggplot(meanDF, aes(x=Species, y=Sepal.Length)) + geom_bar(stat="identity") + ggtitle('default alphabetic order') | |
p2=ggplot(meanDF, aes(x=Species2, y=Sepal.Length)) + geom_bar(stat="identity")+ ggtitle('random order') | |
# make plots | |
grid.arrange(p1, p2, ncol=2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment