繁体   English   中英

ggplot2没有在条形图上绘制第二个因子

[英]ggplot2 not plotting second factor on bar graph

这是我用于创建表的代码:

    cmv2<-ddply(cmv, c("treatment", "year"), summarise,
    mean.num.rattles=mean(plant.tot.rat, na.rm=TRUE),
    sd=sd(plant.tot.rat, na.rm=TRUE),
    n=sum(!is.na(plant.tot.rat)),
    se=sd/sqrt(n))

这产生了一个我想要的表:

    treatment year mean.num.rattles        sd  n        se
1     control 2014         978.5833  727.5570 12 210.02763
2     control 2015        1373.8500 1124.5589 12 324.63219
3  early-high 2014         906.8364  600.2020 11 180.96772
4  early-high 2015         615.7455  373.9880 11 112.76161
5   early-low 2014         655.8500  472.1869 12 136.30863
6   early-low 2015         770.5000  647.2640 10 204.68284
7   late-high 2014         218.4923  260.0087 13  72.11344
8   late-high 2015         865.5833 1317.3728 12 380.29278
9    late-low 2014         461.6667  509.2678 12 147.01296
10   late-low 2015         513.1800  475.1837 10 150.26630

但是,当我尝试通过ggplot代码申请时:

    p<-ggplot(cmv2, aes(x=treatment,y=mean.num.rattles, fill=year))+ 
    geom_bar(stat="identity",fill="white", colour="black", position="dodge")

我得到的图像看起来像这样:

在此处输入图片说明

您知道我的代码出了错吗?

谢谢Sumedh! 该代码最终通过删除代码中不相关的fill =“ white”和colour =“ black”而起作用。 在代码中添加factor(year)也非常重要。

    ggplot(cmv2, aes(x=treatment,y=mean.num.rattles, fill=factor(year)))+ geom_bar(stat="identity",position="dodge")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM