下面的代码可以正常工作,并且可以正确标记条形图,但是,如果我尝试使用geom_text作为直方图,则我失败了,因为geom_text需要y分量,而直方图的y分量是频率,而频率从来都不是代码的一部分,那么我该怎么办直方图的标签?
效果很好
ggplot(csub, aes(x=Year, y=Anomaly10y, fill=pos)) +
geom_bar(stat="identity", position="identity") +
geom_text(aes(label=Anomaly10y,vjust=1.5))
问题-下面的geom_text代码中没有Y分量(由?表示)
ggplot(csub,aes(x=Anomaly10y)) +
geom_histogram()
geom_text(aes(label=?,vjust=1.5))
默认情况下,geom需要x和y分量,
当我没有y分量时,该函数会自动生成该怎么办?
geom_histogram()
只是一个精美的包装器,stat_bin
因此您可以随心所欲地使用自己喜欢的条形文字。这是一个例子
#sample data
set.seed(15)
csub<-data.frame(Anomaly10y = rpois(50,5))
然后我们用
ggplot(csub,aes(x=Anomaly10y)) +
stat_bin(binwidth=1) + ylim(c(0, 12)) +
stat_bin(binwidth=1, geom="text", aes(label=..count..), vjust=-1.5)
要得到
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句