You got this error because p
values are numeric in your data frame but in this case for the fill=
you need discrete values as bars are stacked and will be colored according to p
. Just use as.factor()
around p
.
ggplot(BCIcor,aes(x=cor,fill=as.factor(p)))+geom_histogram(binwidth = 0.2)