Lab 7

Lowes and Population Overlay - With Bonus Walmart

Author

Gabriela Peralta

library(tidyverse)
library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(questionr)
library(viridis)
library(leaflet)
library(tidycensus)

ACQUIRE THE DATA

The following code will read the dataset in directly from data.world.
You may need to join data.world, but I think it works without joining. (Joining is free.)

If you’d rather download and then import, here is the location of the dataset:

https://data.world/data-hut/lowes-location-data

lowesUS <- read.csv("https://query.data.world/s/b6qddeou7l75v46wialbnfl3fiwgf5?dws=00000", header=TRUE, stringsAsFactors=FALSE)

CREATE MAP FOR GEORGIA LOCATIONS

Map Subway store locations JUST FOR in AR using leaflet package.

lowesUS <- lowesUS %>% filter(state == "GA")


lowesUS %>% leaflet(width = "100%") %>% 
             addTiles() %>% 
             setView(-83.5, 32.5, zoom = 6) %>% 
             addMarkers(lat = ~latitude, 
                                 lng = ~longitude, 
                                 popup = lowesUS$name)

The used code helps identify the “Lowe’s” stores in the state of Georgia. I added markers for each store location that helps to see it easily. If one clicks on the marker, it pops up the name fo the county where the store is located. Most of the stores are in north west in Georgia, and they seem to be very close to each other, while they are more spread in the south east. The areas with least “Lowe’s stores can potentially indicate lower accessibility which we can see more of a trend in the center of Georgia. Identifying regions with fewer stores may indicate potential opportunities for the company to expand if there is the presence of a good market for it.

ACQUIRE GEORGIA COUNTY-LEVEL POPULATION DATA FROM THE US CENSUS

Obtain your own census api key at: https://api.census.gov/data/key_signup.html
We will use the api key to directly download population data from the census.

OVERLAY Lowes TO POPULATION

Let’s map the AR Population Census using the leaflet package.
This time we are using a different provider for the map: OpenStreetMap
Try swapping other maps – see a few below in the commented code.

MapPalette <- colorQuantile(palette = "viridis", domain = ar_pop$estimate, n = 20)

ar_pop %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84") %>% 
  leaflet(width = "100%", height = 500) %>% 
addProviderTiles(provider = "Esri.WorldStreetMap") %>% 
  addPolygons(popup = ~NAME,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.6,
              color = ~ MapPalette(estimate)) %>% 
  addLegend("bottomright", 
            pal = MapPalette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
  addCircleMarkers(data = lowesUS, 
                   lat = lowesUS$latitude,
                   lng = lowesUS$longitude,
                   popup = lowesUS$name,
                   weight = 1,
                   radius=4,
                   color = "purple", 
                   opacity = 1)
## Alternative maps  (just swap out the above)
#addProviderTiles(provider = "Esri.WorldStreetMap") %>% 
#addProviderTiles(provider = "OpenStreetMap") %>% 
#addProviderTiles(provider = "Esri.WorldPhysical") %>% 
#addProviderTiles(provider = "Esri.WorldImagery") %>% 
#addProviderTiles(provider = "Esri.WorldTopoMap") %>% 

In this second map, the code is identifying the “Lowe’s” stores present in Georgia and the population percentage in each county. The darker the color, the lower the percentage, and the lighter the color the higher the percentage. Atlanta, which is the capital of Georgia is the most concentrated in population, and then there are small counties such as Houston and Chatham that have the most people. On the other hand, there are counties such as Echols, Baker, Schley, and Glascock that have the least amount of population. One possible reason for their low percentage is due to the small size of the county, therefore it might not have enough land to host more.

ADD ON WALMART LOCATIONS

Note – modified code slightly in the addPolygons() function to outline each county border in gray

CREATE MAP FOR GEORGIA (GA) LOWES LOCATIONS

Map Subway store locations JUST FOR in AR using leaflet package.

library(htmltools)

# Create legend HTML
legend <- tags$div(
  style = "background-color: white; padding: 5px; border-radius: 5px;",
  tags$strong("Legend"), tags$br(),
  tags$svg(height = 10, width = 10,
           tags$circle(cx = 5, cy = 5, r = 4, stroke = "red", "stroke-width" = 1, fill = "red")),
  "Lowe's Stores", tags$br(),
  tags$svg(height = 10, width = 10,
           tags$circle(cx = 5, cy = 5, r = 4, stroke = "blue", "stroke-width" = 1, fill = "blue")),
  "Walmart Stores"
)
walmartUS <- read.csv("https://query.data.world/s/x2vst5f6zlzcdlavosn5q4q6za5omg?dws=00000", header=TRUE, stringsAsFactors=FALSE)
sbar <- walmartUS %>% filter(state == "GA")
rm(walmartUS)
ar_pop %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84") %>% 
  leaflet(width = "100%", height = 500) %>% 
  addProviderTiles(provider = "Esri.WorldStreetMap") %>% 
  addPolygons(popup = ~NAME,
              stroke = TRUE, 
              color = "gray",
              weight = 1,
              smoothFactor = 0,
              fillOpacity = 0.6,
              fillColor = ~ MapPalette(estimate)) %>% 
  addLegend("bottomright", 
            pal = MapPalette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
  addCircleMarkers(data = lowesUS, 
                   lat = lowesUS$latitude,
                   lng = lowesUS$longitude,
                   popup = lowesUS$name,
                   weight = 1,
                   radius = 4,
                   color = "red", 
                   opacity = 1) %>%
  addCircleMarkers(data = sbar, 
                   lat = sbar$latitude,
                   lng = sbar$longitude,
                   popup = sbar$name,
                   weight = 1,
                   radius = 4,
                   color = "blue", 
                   opacity = 1) %>%
  addLegend(position = "bottomright",
            title = NULL,
            colors = c("red", "blue"),
            labels = c("Lowe's Stores", "Walmart Stores"),
            opacity = 1,
            labFormat = htmltools::HTML(legend))

In this map I am comparing the presence of Walmart to Lowe’s in the state of Georgia. Clearly Walmart doubles Lowe’s, and just as the Lowe’s store location trend, Walmart follows the same having the most locations in North West of Georgia. The little blue circles are Walmart locations, and the red ones that are hard to see are Lowe’s locations. Some of the reasons why there are more Walmart’s than Lowe’s is due to the Market demand, since Walmart offer a wide range of goods, that attracts more customers. On the other hand, Lowe’s might have more competitors that make it difficult for them to set more stores around. There are demographic factors to consider such as population density, income levels, and consumer preferences. Walmart chooses to locate stores in areas with higher population density or lower-income demographics where their low price appeal to a larger customer base. Overall, the difference in the number of Walmart and Lowe’s locations in Georgia is likely influenced by a combination of factors related to business strategy, market demand, competition, real estate considerations, and demographic facors.