2017-06-13 148 views
-1

我無法在ggplot上製作分組條形圖。我不知道如何在barplot上設置y軸。我已經嘗試了熔化()函數,但無法做到這一點。如何在ggplot分組條形圖上設置x-y軸?

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 
+1

使用'geom_col()'或'geom_bar(STAT = 「身份」)' – yeedle

回答

3

無需融化,您的數據已經以適當的格式。

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

enter image description here

+0

我很感激@neilfws,有很大的幫助! – nguy321

+0

我仍然與y軸標籤掙扎。我不能將它添加到情節,我不知道爲什麼。 ggplot(mip,aes(Manejo,Abundancia), horiz = TRUE)+ labs(y =「Abundancia」)+ scale_y_continuous(breaks = c(0,250,1000,2000,3000,4000,5000,6000,7000, 8000,9000,10000,11000,12000,13000,14000,15000),標籤(「250」,「500」,「750」,「1000」))+ geom_col(aes(fill = Estadio)) > – nguy321

+0

I認爲你需要從'scale_y_continuous'中移除'labels(...)'。 – neilfws

相關問題