Reputation: 13
This is my first post. Hope you can help. My data set:
spe <- c(rep("spe1",3),rep("spe2",5))
site <-c("site1","site1","site1","site1","site2","site2","site2","site2")
prey1 <- c(1,4,5,3,0,0,3,1)
prey2 <- c(0,0,5,4,2,1,1,0)
prey3 <- c(0,1,1,0,14,11,0,0)
df <- data.frame(spe,site, prey1,prey2,prey3)
library(reshape2)
df1<-melt(df)
ggplot(df1, aes(x=variable, y=value, fill=spe))+
geom_bar(position="dodge",stat = "identity")
The values at the y axes does not represent the real value(sum). Prey1 ~ spe1 should be 10 not 5.
Upvotes: 1
Views: 34
Reputation: 4592
ggplot(df1, aes(x=variable, y=value, fill=spe))+
stat_summary(geom = "bar", fun.y = "sum", position = "dodge")
Upvotes: 1