0

I'd like to change the color of the following grouped barplot such that each specie has the same color, regardless of condition.

# 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")

current output:

enter image description here

desired output:

enter image description here

Laura
  • 61
  • 1
  • 11

1 Answers1

0

You can set condition as a group and keep fill as specie:

# Grouped
ggplot(data, aes(group = condition, fill=specie, y=value, x=specie)) + 
  geom_bar(position="dodge", stat="identity")
Pete900
  • 2,016
  • 1
  • 21
  • 44