I have a short R script which plots a few histograms using ggplot2. How can I automatically set the ymax limit in the histogram based on the maximum frequency in the histogr
Personally, I find the 'hist' function to be the most useful for these sorts of calculations. The 'hist' function is super fast and can provide your frequency counts. For your case, you could do something like this:
max(hist(data$myo_activity, breaks=seq(range_Min, range_Max, by=bin_Width), plot=FALSE)$counts)
Where range_Min is the bottom of your theoretical range (i.e. 0), and range_Max is the upper limit above your theoretically range. bin_Width is the value width of each frequency count.
The equation should give you the max value you need to specify the plot range. I believe the 'ggplot' function is calling the 'hist' function anyway, so I prefer to call it directly when I'm only wanting the data.