Here's my task:
Create the following graph:
- Group the Pokemon data by type1 and is_legendary
- Summarize the data with the mean of the attack
- Create a bar chart with type1 on the x, the mean of the attack on the y and type one of the fill
- Change the colors of the type one to be type_color
- facet_wrap it so that there are different bar charts for the regular and legendary pokemon
I am able to summarize the data by the mean of the attack, but it is not a column in my dataset. How do I make it so the mean of the attack is the y aesthetic? Am I overlooking a simpler way?
I have tried making a new column on the original Pokemon dataset, but that would create a mean of all of the data and not group it by type1 or is_legendary.
I also keep getting the error: Error: stat_count() must not be used with a y aesthetic. But when I look up that error, I can't see how it applies to this particular issue.
pokemon$type1 <- factor(pokemon$type1)
pokemon$is_legendary <- factor(pokemon$is_legendary)
pokemon %>%
group_by(type1, is_legendary) %>%
summarize(mean_attack = mean(attack)) %>%
ggplot(mapping = aes(x = type1, y = mean_attack, fill = type1)) + geom_bar()
+ scale_fill_manual(values = type_color) + facet_wrap(~ is_legendary)
+ labs(title = "Average Attack of Legendary and Regular Pokemon") + pokemon.theme