install.packages(“leaflet”)
install.packages(“readxl”)
library(leaflet)
library("readxl")
Location <- read_excel("NFL_Teams.xlsx")
head(Location)
## # A tibble: 6 x 3
## Team latitude longitude
## <chr> <dbl> <dbl>
## 1 Titans 36.2 -86.8
## 2 Giants 40.8 -74.1
## 3 Steelers 40.4 -80.0
## 4 Panthers 35.2 -80.9
## 5 Ravens 39.3 -76.6
## 6 Buccaneers 28.0 -82.5
Team_icons <- icons(
iconUrl = ifelse(Location$Team=="Steelers", "steelers.png",
ifelse(Location$Team=="Browns","browns.png",
ifelse(Location$Team=="Bengals","bengals.png",
ifelse(Location$Team=="Ravens","ravens.png",
ifelse(Location$Team=="Bears","bears.png",
ifelse(Location$Team=="Texans","texans.png",
ifelse(Location$Team=="Chiefs","chiefs.png",
ifelse(Location$Team=="Saints","saints.png",
ifelse(Location$Team=="Dolphins","dolphins.png",
ifelse(Location$Team=="Buccaneers","bucs.png",
ifelse(Location$Team=="Falcons","falcons.png",
ifelse(Location$Team=="Bills","bills.png",
ifelse(Location$Team=="Forty-Niners","49ers.png",
ifelse(Location$Team=="Rams","rams.png",
ifelse(Location$Team=="Jaguars","jaguars.png",
ifelse(Location$Team=="Eagles","eagles.png",
ifelse(Location$Team=="Seahawks","seahawks.png",
ifelse(Location$Team=="Raiders","raiders.png",
ifelse(Location$Team=="Cowboys","cowboys.png",
ifelse(Location$Team=="Panthers","panthers.png",
ifelse(Location$Team=="Patriots","patriots.png",
ifelse(Location$Team=="Colts","colts.png",
ifelse(Location$Team=="Vikings","vikings.png",
ifelse(Location$Team=="Redskins","washington.png",
ifelse(Location$Team=="Titans","titans.png",
ifelse(Location$Team=="Chargers","chargers.png",
ifelse(Location$Team=="Broncos","broncos.png",
ifelse(Location$Team=="Lions","lions.png",
ifelse(Location$Team=="Packers","packers.png",
ifelse(Location$Team=="Cardinals","cardinals.png",
ifelse(Location$Team=="Giants", "giants.gif",
ifelse(Location$Team=="Jets","jets.png", "")))))))))))))))))))))))))))))))), iconWidth = 28, iconHeight = 35,
iconAnchorX = 18, iconAnchorY = 34,
shadowWidth = 20, shadowHeight = 34,
shadowAnchorX = 4, shadowAnchorY = 32)
Team <- as.character(Location$Team)
df <- data.frame(lat=Location$latitude, lng = Location$longitude)
df %>%
leaflet() %>%
addTiles() %>%
addMarkers(icon=Team_icons, popup=Team,clusterOptions = markerClusterOptions())