Reputation: 1147
Why am I getting this ymax
error when doing the following graph in ggplot2? I am trying to create a histogram with some data labels.
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()
Can someone explain to me what the ymax
parameter is too?
Upvotes: 0
Views: 100
Reputation: 1147
This can be fixed by doing:
ggplot(df,aes(x= len, ymax=max(..count..))) +
stat_bin(geom="bar", binwidth=5, aes(fill=..count..), colour="black")
So by putting the ymax
parameter in the aes
and setting it to ..count..
in the situation where you are using stat_bin
.
Upvotes: 0