Skip to content

Instantly share code, notes, and snippets.

@aurielfournier
Created January 16, 2018 15:55
Show Gist options
  • Save aurielfournier/565b34058f5879bef97322ff8f9926f7 to your computer and use it in GitHub Desktop.
Save aurielfournier/565b34058f5879bef97322ff8f9926f7 to your computer and use it in GitHub Desktop.
library(ggplot2)
dat <- data.frame(bars = rep(c("a","b","c","d"), each=3),
stacks = rep(c("a","b","c"), times=4),
value = c(20,60,20,10,70,20,70,10,20,40,40,20))
dat$stacks <- as.character(dat$stacks)
ggplot(data=dat, aes(x=bars, y=value, fill=stacks))+
geom_bar(stat="identity")
correctorder <- c("c","b","a")
dat$stacks <- factor(dat$stacks, levels=correctorder)
ggplot(data=dat, aes(x=bars, y=value, fill=stacks))+
geom_bar(stat="identity")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment