library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.5
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.5

Introduction

This data set is provided by https://raw.githubusercontent.com/jokecamp/FootballData/master/other/stadiums-with-GPS-coordinates.csv which gives the coordinates for the football teams spanning across different leagues in different countires such as England, France, Spain, Scotland and Germany.

url_data <- read.csv("https://raw.githubusercontent.com/jokecamp/FootballData/master/other/stadiums-with-GPS-coordinates.csv")

df <- url_data[!is.na(url_data$Longitude)&!is.na(url_data$Latitude),]

Structure of the dataset.

str(df)
## 'data.frame':    136 obs. of  8 variables:
##  $ Team     : chr  "Arsenal " "Aston Villa " "Blackburn Rovers " "Bolton Wanderers " ...
##  $ FDCOUK   : chr  "Arsenal" "Aston Villa" "Blackburn" "Bolton" ...
##  $ City     : chr  "London " "Birmingham " "Blackburn " "Bolton " ...
##  $ Stadium  : chr  "Emirates Stadium " "Villa Park " "Ewood Park " "Reebok Stadium " ...
##  $ Capacity : int  60361 42785 31154 28100 42449 40157 25700 45276 47405 75811 ...
##  $ Latitude : num  51.6 52.5 53.7 53.6 51.5 ...
##  $ Longitude: num  -0.109 -1.885 -2.489 -2.536 -0.191 ...
##  $ Country  : chr  "England" "England" "England" "England" ...

Creating Leaflet

We will now be creating a leaflet showing the locations of all the major football stadiums in Europe for each of the teams.

df %>% 
  leaflet() %>% 
  addTiles() %>% 
  addMarkers(popup=df$Team , clusterOptions=markerClusterOptions())
## Assuming "Longitude" and "Latitude" are longitude and latitude, respectively