2015-06-21 68 views
0

为什么在ggplot2中执行以下图形时出现此错误ymax?我正尝试用一些数据标签创建直方图。ymax error with stat_bin

require(ggplot2) 
df=data.frame(ToothGrowth) 
ggplot(df,aes(x= len)) + 
    stat_bin(geom="bar", binwidth=5, aes(fill=..count..), colour="black") + 
    stat_bin(binwidth=5, geom="text", aes(label=..count..), vjust=-1.5) + 
    facet_grid(.~supp)+ 
    ylim(c(0,15))+ 
    theme_bw() 

有人可以向我解释ymax参数是什么吗?

+0

这是一个警告,而不是错误,请参阅http://stackoverflow.com/questions/16821339/how-to-solve-the-ymax-not-defined –

回答

0

这可以固定做:

ggplot(df,aes(x= len, ymax=max(..count..))) + 
    stat_bin(geom="bar", binwidth=5, aes(fill=..count..), colour="black") 

所以通过将ymax参数在aes并把它置..count..在您使用stat_bin的情况。