简体   繁体   English

如何在ggplot分组条形图上设置x-y轴?

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

I'm having trouble making a grouped bar chart on ggplot. 我在制作ggplot上的分组条形图时遇到麻烦。 I don't know how to set the y axis on the barplot. 我不知道如何在小节上设置y轴。 I've tried with melt() function, yet couldn't do it. 我已经尝试过melt()函数,但无法做到。

The x axis is already set, now I need to set the variable "ab" as the y axis. x轴已经设置,现在我需要将变量“ ab”设置为y轴。 Could anyone help me out? 有人可以帮我吗?

Thanks a lot, much appreciated! 非常感谢,非常感谢!

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

No need to melt, your data are already in an appropriate format. 无需融合,您的数据已经采用了适当的格式。

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