R: ggplot2: Adding count labels to histogram with density overlay -


I have a time series that I am checking for data diversity, and to explain some important aspects of this I want to have data analyzer I have a density histogram from a KDE plot (clearly to see both plots), though the original data matters, and I want to keep counting values ​​as the label above histogram bars.

Here are some code:

  $ tix_hist & lt; - ggplot (tix, aes (x = Tix_Cnt)) + geom_histogram (AES (y = ..density ..), color = "black", fill = "orange", dosage = 50) + xlab ("bin") + Ylab ("density") + GOM density (AES (y = .. density ..), fill = NA, color = "blue") + scale_x_continuous (brakes = cic (1,1700, = 100 =)) tix_hist + opts (Title = "ticket density to date", plot.title = theme_text (face = "bold", size = 18), axis.title.x = theme_text (face = "bold", size = 16), axis.title .y = Theme_text (face = "bold", size = 14, angle = 90), axis Text.x = theme_text (face = "bold", size = 14), axis-text.y = theme_text (face = " Bold ", size = 14))   

I thought about extrapolating count values ​​using the KDE bandwidth, etc. Is it possible to have the data frame as the digital output of the GGLot frequency histogram and add it as 'Layer'? I'm not yet on the layer () function, but any suggestions would be useful thanks so much!

If you want to show y-axis to bin_count number At the same time, by adding the density curve to this histogram,

you can first use geom_histogram () and record binwidth value! (This is very important!), Add a layer of geom_density () to show the fitting curve again.

If you do not know how the binwidth value, you can just calculate:

  my_binwidth = (max (Tix_Cnt) -min ( Tix_Cnt)) / 30;   

(This is what geom_histogram is by default.)

The code is given below:

(Suppose that binwith is the value you just calculated is 0.001)

  tix_hist & lt; - ggplot (tix, aes (x = Tix_Cnt)); Tix_hist & lt; - tix_hist + geom_histogram (AES (y = .. count ..), color = "blue", fill = "white", dosage = 0.001); Tix_hist & lt; - tix_hist + geom_density (AES (y = 0.001 * .. count ..), alpha = 0.2, fill = "# FF6666", adjust = 4); Print (tix_hist);    

Comments