【发布时间】:2021-10-21 00:14:09
【问题描述】:
我正在尝试使用 ggplot 2 制作简单的条形图,但未能成功 我的数据是
dput(Success)
structure(list(Species = c("b", "c", "g", "g, b", "m"), n = c(586L,
5L, 293L, 4L, 8L), Success = c(412L, 5L, 186L, 4L, 6L)), row.names = c(NA,
-5L), class = "data.frame")
我做了以下情节
Speciesplot<-ggplot(Success, aes(Species, n, fill = Species)) + geom_bar(stat = "identity") +
scale_x_discrete(labels = c("Blue tit", "Coal tit", "Great tit", "Mixed Broods (G,B)", "Marsh tit")) +
scale_y_continuous(breaks = seq(0, 600, by = 50)) +
scale_fill_manual(values=c("dodgerblue", "gray", "chartreuse4", "red", "lightgoldenrod"))+
theme(element_blank())+
ggtitle("Number of nests by species")+
ylab("Number of nests")+
theme(legend.position = "none")+
geom_text(aes(label=n), position=position_dodge(width=0.9), vjust=-0.25)
这给了
我现在要做的就是将Success 数据添加到此条形图上
这样我就可以在条形图上显示成功嵌套的数量(如堆叠的条形图),但据我所知,int 类数据是不可能的。我在这里缺少什么,我尝试制作一个新的条形图并将其添加到 Speciesplot 但我也无法让它工作。
【问题讨论】: