如何在 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")
我在 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")