我正在处理以下数据框(df):
df$GP<-c(0,0,0,1,1,2,3,3,3,3,4,4,9,15,18,18,19,19,20,20,21,22,22,23)
df$colour<-c("g","g","g","g","g","g","g","g","g","g","g","g","t","t","g","g","g","g","g","g","g","g","g","g")
我想要下面的直方图,但是显示colour=="g"
和colour=="t"
的填充不同。
但是,运行以下代码,标为colour=="t"
的条形图将超出比例(最大为1-plot2),而应为0.25(plot1)。
ggplot(data=df,aes(x=GP,y=..ndensity..))+geom_histogram(bins=25,aes(fill=colour))+scale_fill_manual(values=c("black","grey"))
您对如何实现此目标有任何想法吗?
非常感谢您提供的帮助!