-
-
Save swuyts/492f52d2890ae1d7101ff859f4bac4a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table %>% | |
arrange(age) %>% # Sort on age | |
.[1:10,] %>% # Select top 10 | |
mutate(Player = factor(str_c(Player, "(", age,")"))) %>% # Add age to the players name for plotting | |
ggplot(aes(x = fct_reorder(Player, Goals), y = Goals)) + # Start plotting | |
geom_col(aes(fill = team)) + # Add bars | |
geom_text(aes(y = -0.3, label = position, colour = team)) + # Add text that shows their position | |
scale_colour_brewer(palette = "Dark2") + # Change colour scheme | |
scale_fill_brewer(palette = "Dark2") + # Change colour scheme | |
coord_flip() + # Flip x and y axis | |
xlab("") + # remove label on y-axis | |
ggtitle("Youngest players in the World Cup") + # Add title to the plot | |
theme_minimal() + # Use a different theme | |
theme(panel.grid = element_blank()) # Tweak the theme a little bit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment