Introduction

For this final project, we were asked to create a webpage under these instructions.

  1. Create a web page using R Markdown that features a map created with Leaflet.
  2. Host your webpage on either GitHub Pages, RPubs, or NeoCities.
  3. Your webpage must contain the date that you created the document, and it must contain a map created with Leaflet. I would love to see you show off your creativity!

Data Preperation

I have decided to display a map with the locations of all 32 NFL teams and their stadiums. Football is my favorite sport, so I thought it would be neat to use something related to it as my data. I got the data from https://public.opendatasoft.com/explore/dataset/stadiums_nfl/download/?format=csv&timezone=America/New_York&use_labels_for_header=true , but used the file from my working directory in my code.

setwd("C:/Users/hunte/Documents/R")
nfl <- read.csv("stadiums_nflclean.csv")

Since the data was recorded in 2010, I had to go through and update the stadiums that have been built since.That is where the nfl_clean.csv file comes from. Here is the structure of the clean data.

str(nfl)
## 'data.frame':    30 obs. of  4 variables:
##  $ ï..NAME   : Factor w/ 30 levels "Allegiant Stadium",..: 16 27 4 13 28 9 25 26 5 30 ...
##  $ LATITUDE  : num  39.9 34 35.2 30.3 41.9 ...
##  $ LONGTITUDE: num  -75.2 -118.3 -80.9 -81.6 -87.6 ...
##  $ TEAM      : Factor w/ 30 levels "Arizona Cardinals",..: 24 17 5 15 6 21 4 28 27 20 ...

Making individual value characteristics made it easier later on to name where I wanted the popups to come from and so forth.

nfl_team <- as.character(nfl$TEAM)
nfl_name <- as.character(nfl$ï..NAME)
nfl_df <- data.frame(lat=nfl$LATITUDE, long=nfl$LONGTITUDE)

Actual Map

Using the leaflet library, I was able to create a map with markers indicating the locations of all 32 NFL Stadiums.

library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.3
nfl_df %>%
  leaflet() %>%
  addTiles() %>%
  addMarkers(popup=paste("Team:", nfl_team, "<br>", "Stadium:", nfl_name))

I also added popups letting you know what team resided in the marker as well as the stadium name.

Conclusion

I think this came out very well. The hardest part was finding a dataset that was up to date with all of the new stadiums that have been built over the last decade. Manually cleaning up the data and updating the new values took some time but after that leaflet did the rest.