簡體   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