Skip to content

Instantly share code, notes, and snippets.

@swuyts
Created June 14, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swuyts/492f52d2890ae1d7101ff859f4bac4a6 to your computer and use it in GitHub Desktop.
Save swuyts/492f52d2890ae1d7101ff859f4bac4a6 to your computer and use it in GitHub Desktop.
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