Introduction

Currently, during the Covid-19 outbreak, there has been an increased need to reach essential services, such as grocery stores. In light of this, I decided to download a dataset that had all Walmart locations within the United States, and then created a leaflet mapping of all the stores, along with each stores relevant information.

Data Preparation

For this assignment, I retrieved my data from https://data.world/data-hut/walmart-store-location-dat.

wm<-read.csv("https://query.data.world/s/ygowvkrudsumz2m3wfr4s43dgkgrj2", header=TRUE, stringsAsFactors=FALSE);

library(leaflet)
library(tidyverse)

Here is the structure of the dataset:

str(wm)
## 'data.frame':    4654 obs. of  22 variables:
##  $ name          : chr  "Conway Supercenter" "Sikeston Supercenter" "Tahlequah Supercenter" "Mountain Home Supercenter" ...
##  $ url           : chr  "https://www.walmart.com/store/5/conway-ar/details" "https://www.walmart.com/store/9/sikeston-mo/details" "https://www.walmart.com/store/10/tahlequah-ok/details" "https://www.walmart.com/store/11/mountain-home-ar/details" ...
##  $ street_address: chr  "1155 Hwy 65 North" "1303 S Main St" "2020 S Muskogee Ave" "65 Wal Mart Dr" ...
##  $ city          : chr  "Conway" "Sikeston" "Tahlequah" "Mountain Home" ...
##  $ state         : chr  "AR" "MO" "OK" "AR" ...
##  $ zip_code      : int  72032 63801 74464 72653 74017 64836 72756 72761 65536 65775 ...
##  $ country       : chr  "US" "US" "US" "US" ...
##  $ phone_number_1: chr  "501-329-0023" "573-472-3020" "918-456-8804" "870-492-9299" ...
##  $ phone_number_2: logi  NA NA NA NA NA NA ...
##  $ fax_1         : logi  NA NA NA NA NA NA ...
##  $ fax_2         : logi  NA NA NA NA NA NA ...
##  $ email_1       : logi  NA NA NA NA NA NA ...
##  $ email_2       : logi  NA NA NA NA NA NA ...
##  $ website       : logi  NA NA NA NA NA NA ...
##  $ open_hours    : chr  "monday - friday : 00:00-24:00, saturday : 00:00-24:00, sunday : 00:00-24:00" "monday - friday : 00:00-24:00, saturday : 00:00-24:00, sunday : 00:00-24:00" "monday - friday : 00:00-24:00, saturday : 00:00-24:00, sunday : 00:00-24:00" "monday - friday : 00:00-24:00, saturday : 00:00-24:00, sunday : 00:00-24:00" ...
##  $ latitude      : num  35.1 36.9 35.9 36.4 36.3 ...
##  $ longitude     : num  -92.4 -89.6 -95 -92.3 -95.6 ...
##  $ facebook      : logi  NA NA NA NA NA NA ...
##  $ twitter       : logi  NA NA NA NA NA NA ...
##  $ instagram     : logi  NA NA NA NA NA NA ...
##  $ pinterest     : logi  NA NA NA NA NA NA ...
##  $ youtube       : logi  NA NA NA NA NA NA ...

These lines of code remove any na variables from the longitude/latitude data columns and also creates a variable which will hold the url links to the various walmart stores.

 wm <- wm[!is.na(wm$longitude)&!is.na(wm$latitude),]
maplinks<-wm$url

Mapping Clusters

Since there are over 4600 Walmart stores, the cluster feature was a critical component to creating this leaflet map. In addition to this, the popup argument in leaflet was used thoroughly, to include all relevant information that may be needed about a Walmart store(i.e. Store name, website, address, city, phone number, etc). In addition, the website links are fully functional.

wm %>%
leaflet() %>%
  addTiles() %>% 
  addMarkers(lng = wm$longitude, lat = wm$latitude,popup = paste("<strong", wm$name,">",wm$name, "</strong><br>","Open Hours (in military time):",wm$open_hours,"<br>","Website: <a href=", maplinks,">", maplinks, "</a><br>" ,
"Phone Number:", wm$phone_number_1,"<br>",
"Address:", wm$street_address, "<br>",
"City:", wm$city, "<br>",
"State:", wm$state, "<br>",
"Zip:", wm$zip_code, "<br>",
"Country:", wm$country, "<br>"), clusterOptions=markerClusterOptions())

Conclusion

Based on the information presented here, it is easy to see the relative power of the leaflet package, and its incredible ease of use. In addition, this map could be improved upon at a later date to include other grocery stores, which will help to increase its usefulness.