Reputation:
I have again a problem with creating a bar char in R.
The dataset is now like this:
Age | Season | Gender | count |
---|---|---|---|
10-15 | Fall | male | 60 |
10-15 | Spring | male | 80 |
10-15 | Summer | male | 100 |
10-15 | Winter | male | 50 |
10-15 | Fall | female | 60 |
10-15 | Summer | female | 50 |
10-15 | Spring | female | 40 |
10-15 | Winter | female | 50 |
16-30 | Fall | male | 60 |
16-30 | Spring | male | 80 |
16-30 | Summer | male | 100 |
16-30 | Winter | male | 50 |
16-30 | Fall | female | 60 |
16-30 | Summer | female | 150 |
16-30 | Spring | female | 40 |
16-30 | Winter | female | 50 |
Now I want to create a bar chart with this code:
df %>%
ggplot(aes(x1 = Age,x2=Gender y = count)) +
geom_col() +
facet_wrap(~Season)
But I can't create a bar chart with gender and age in x-Axis and Season. A bar chart that shows gender and age and season.
Upvotes: 0
Views: 38
Reputation: 41285
What you could do is fill
your age column in the bars using this code:
library(tidyverse)
df %>%
ggplot(aes(x = Gender, y = count, fill = Age)) +
geom_col() +
facet_wrap(~Season)
Output:
Upvotes: 0