You can use the hist function, which calculates the counts. Just make sure you give it the same bunker breaks as the geom_histogram. If there is no binary width for geom_histogram, the default range is / 30. From a look at how geom_histogram generates boxes, I think this should work:
require(plyr) min.brea <- round_any(min(df$x), diff(range(df$x))/30, floor) max.brea <- round_any(max(df$x), diff(range(df$x))/30, ceiling) breaks <- seq(min.brea, max.brea, diff(range(df$x/30))) histdata <- hist(df$x, breaks=breaks, plot=FALSE, right=FALSE) max.value <- max(histdata$counts)
round_any function from plyr.
user1305494
source share