Im trying to recreate the following histogram with ggplot2 but without success.
set.seed(1234)
df <- data.frame(result=floor(rnorm(1000, 100, 20)))
h <- hist(df$result, plot=FALSE, breaks=20)
# Selected breaks
brks <- c(80,85,90)
cols <- rep("lightblue", length(h$breaks))
# Find bars corresponding to breaks
brk_bars <- h$breaks %in% brks
cols[brk_bars] <- "darkblue"
plot(h, col=cols, main="")
I use:
library(ggplot2)
ggplot(h)+
geom_histogram(color=cols)
but Im getting Error:
datamust be a data frame, or other object coercible by
fortify(), not an S3 object with class histogram