簡體   English   中英

如何在ggplot分組條形圖上設置x-y軸?

[英]How to set x - y axis on ggplot grouped bar chart?

我在制作ggplot上的分組條形圖時遇到麻煩。 我不知道如何在小節上設置y軸。 我已經嘗試過melt()函數,但無法做到。

x軸已經設置,現在我需要將變量“ ab”設置為y軸。 有人可以幫我嗎?

非常感謝,非常感謝!

dataset
    ab  estadio manejo
1   2506    Huevos  mip
2   8616    Ninfas  mip
3   229 Adultos mip
4   2183    Ninfas3-5   mip
5   134 Ninfaspar   mip
6   1382    Huevos  nomip
7   3481    Ninfas  nomip
8   73  Adultos nomip
9   833 Ninfas3-5   nomip
10  na  Ninfaspar   nomip


> ggplot(mip,aes(x=estadio,fill=manejo, y=ab))+geom_bar(position="stack")+labs(title="MIP")
Error: stat_count() must not be used with a y aesthetic.

*2nd time
> df1<-melt(mip,id="ab")
Warning message:
attributes are not identical across measure variables; they will be dropped 

> ggplot(df1,aes(estadio,ab,fill=manejo)) + geom_bar(position="stack") + labs(title="MIP")
Error in FUN(X[[i]], ...) : objeto 'estadio' no encontrado

無需融合,您的數據已經采用了適當的格式。

ggplot(mip, aes(estadio, ab)) + 
geom_col(aes(fill = manejo)) + 
labs(title = "MIP")

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM