Skip to content

Instantly share code, notes, and snippets.

@rbbernardino
Created August 10, 2018 22:54
Show Gist options
  • Save rbbernardino/ee6defe24b72e0d462e589e0cc85f1fd to your computer and use it in GitHub Desktop.
Save rbbernardino/ee6defe24b72e0d462e589e0cc85f1fd to your computer and use it in GitHub Desktop.
# library
library(ggplot2)
# create a dataset
specie=c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition=rep(c("normal" , "stress" , "Nitrogen") , 4)
value=abs(rnorm(12 , 0 , 15))
data=data.frame(specie,condition,value)
# Grouped
ggplot(data, aes(fill=condition, y=value, x=specie)) +
    geom_bar(position="dodge", stat="identity")
# Stacked
ggplot(data, aes(fill=condition, y=value, x=specie)) +
    geom_bar( stat="identity")
# Stacked Percent
ggplot(data, aes(fill=condition, y=value, x=specie)) +
    geom_bar( stat="identity", position="fill")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment