Site icon R-bloggers

The Growth of Soccer (1872 – Present)

[This article was first published on World Soccer Analytics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Soccer (football) is one of the world’s most popular sports, played and watched by millions of people all around the world. But while today it is played in virtually every country, it hasn’t always been that way.

As you can see in the animated map below, soccer started off as a small sport, segregated to the United Kingdom, but has since become a world phenomenon.

A few interesting stats to note:

 

Code Snippets:

df <- read_csv("results.csv")
df$year % year()
df_by_year % count(city,country,year)

df_by_year$city_country <- paste(df_by_year$city,", ", 
df_by_year$country, sep="")


for(i in 1:nrow(df_by_year)){
 result <- geocode(df_by_year$city_country[i], 
 output = "latlona", 
 source = "google",
 override_limit = TRUE)
 df_by_year$lon[i] <- as.numeric(result[1])
 df_by_year$lat[i] <- as.numeric(result[2])
}

df_by_year_all <- df_by_year %>% 
tidyr::complete(nesting(city, 
lon, 
lat), 
year,
fill = list(n = 0))

df_by_year_all <- df_by_year_all %>% group_by(city,lat,lon) %>%
mutate(cs=cumsum(n))


saveGIF({
for (i in 1872:2018) {

year_games <- as.character(i)

year_data <- df_by_year_all %>% filter(year == i,
cs>0)
gg <- ggplot() +
borders("world", colour="gray40", fill="beige") +
theme_map()

final_map <- gg + geom_point(data=
year_data,
aes(x = lon, 
y = lat) ,
alpha = 0.5, 
colour = "darkred") + 
ggtitle(paste0('International Soccer Matches, 1872 - ', year_games)) + 
theme(legend.position="none")+theme(plot.title = element_text(size = 25, face= "bold",
hjust = 0.5))

print(final_map)

}
}, movie.name = 'world_cup_matches_wordpress1.gif', 
interval = 0.2, ani.width = 1000, ani.height = 700)

 

For the full code, please refer to: https://github.com/stefangouyet/How-Soccer-Grew

 

To leave a comment for the author, please follow the link and comment on their blog: World Soccer Analytics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.