Hi all
Having an issue in ggplot.
I am trying to put a gradient scale on my histogram, however I am encountering an error which states:
Error: Aesthetics must be valid computed stats. Problematic aesthetic(s): fill = ..count...
Did you map your stat in the wrong layer?
The data in the dataframe is just a column with continuous numbers from 0 to 204
Here is my ggplot code
df2 %>% ggplot(aes(data,fill=..count..)) + geom_histogram(binwidth = 1)+ scale_fill_gradient(low="lightblue",high="blue")+ geom_text(label="binwidth = 1",x = 50,y = 3000)+ theme_bw()
The weird thing is when I use qplot, it comes out perfectly:
qpplot <- qplot(df2$data, fill=..count.., geom="histogram",xlim=c(0,204)) qpplot + scale_fill_gradient(low="lightblue",high="darkblue")
What am i doing wrong with my ggplot coding?