I have a time-series that I\'m examining for data heterogeneity, and wish to explain some important facets of this to some data analysts. I have a density histogram overlaye
if you want the y-axis to show the bin_count
number, at the same time, adding a density curve on this histogram,
you might use geom_histogram()
first and record the binwidth
value! (this is very important!), next add a layer of geom_density()
to show the fitting curve.
if you don't know how to choose the binwidth
value, you can just calculate:
my_binwidth = (max(Tix_Cnt)-min(Tix_Cnt))/30;
(this is exactly what geom_histogram
does in default.)
The code is given below:
(suppose the binwith
value you just calculated is 0.001)
tix_hist <- ggplot(tix, aes(x=Tix_Cnt)) ;
tix_hist<- tix_hist + geom_histogram(aes(y=..count..),colour="blue",fill="white",binwidth=0.001);
tix_hist<- tix_hist + geom_density(aes(y=0.001*..count..),alpha=0.2,fill="#FF6666",adjust=4);
print(tix_hist);