[英]making a barplot with dodged variables
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). y 轴上的值不代表实际值(总和)。 Prey1 ~ spe1 should be 10 not 5. Prey1 ~ spe1 应该是 10 而不是 5。
ggplot(df1, aes(x=variable, y=value, fill=spe))+
stat_summary(geom = "bar", fun.y = "sum", position = "dodge")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.