I am working with a dataset that includes the age of some people. I am trying to create a histogram for the ages of the people with ggplot in which the colours of the bars of the histogram should depend on some predefined age intervals.
So for example imagine a dataset like this:
>X
Age Age2
10 Under 14
11 Under 14
10 Under 14
13 Under 14
20 Between 15 and 25
21 Between 15 and 25
35 Above 25
I have tried to do something like this:
ggplot(X, aes(x = Age)) + geom_histogram(aes(fill = Age2))
But it displays the following error message:
Error: StatBin requires a continuous x variable the x variable is discrete. Perhaps you want stat="count"?
What am I doing wrong?