DAT-4313 - LAB 7

LUCKY SUPERMARKET DATASET

Author

Robin Chavez

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

Get the data

LuckyUS <- read.csv("https://query.data.world/s/24f7zoc3gw5dqz6fv4opsb3tseboqw?dws=00000", header=TRUE, stringsAsFactors=FALSE)
LuckyUS <- LuckyUS %>% filter(state == "CA")

LuckyUS %>% leaflet(width = "100%") %>% 
  addTiles() %>% 
  setView(-119.4179, 36.7783, zoom = 6) %>%  # Set coordinates for California
  addMarkers(lat = ~latitude, 
             lng = ~longitude, 
             popup = ~name)

Insights Map 1

  1. Concentration in Northern California: There seems to be a higher concentration of Lucky Supermarkets in the northern part of the state, particularly around the San Francisco Bay Area. This could be due to several factors, such as higher population density, greater disposable income, or established brand presence in the region.
  2. Presence in Major Cities: Lucky Supermarkets appear to be located in major cities throughout California, including Sacramento, Fresno, and Los Angeles. This suggests a focus on serving urban and suburban populations.
  3. Limited Presence in Rural Areas: The map shows fewer markers in rural areas of California, particularly in the north and central parts of the state. This could indicate a strategic decision to focus on areas with higher customer density or logistical challenges of operating stores in remote locations.
MapPalette <- colorQuantile(palette = "viridis", domain = ca_pop$estimate, n = 20)

ca_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 = LuckyUS, 
                   lat = LuckyUS$latitude,
                   lng = LuckyUS$longitude,
                   popup = LuckyUS$name,
                   weight = 1,
                   radius=4,
                   color = "red", 
                   opacity = 1)
customIcon <- makeIcon(
  iconUrl = "https://dynl.mktgcdn.com/p/jOufL-m80j0MUjs-k57WtCqKN_XSLouJm_eMiILm0RU/400x227.png",  
  iconWidth = 20,  
  iconHeight = 20 
)

ca_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) %>% 
  addMarkers(data = LuckyUS, 
             lat = LuckyUS$latitude,
             lng = LuckyUS$longitude,
             popup = LuckyUS$name,
             icon = customIcon)  

Insights Map 2

  1. Lucky Supermarkets in Populous Areas: There seems to be a correlation between Lucky Supermarket locations and areas with higher population density. Many of the supermarkets are concentrated in darker green areas, particularly in the San Francisco Bay Area, Los Angeles, and Sacramento. This suggests Lucky Supermarkets might prioritize placing stores in areas with a larger customer base.
  2. Potential Targeting: Since some Lucky Supermarkets are located in less densely populated areas (lighter green), there could be other factors influencing store placement besides population density. These might include factors like proximity to competitors, underserved communities, or strategic locations along major transportation routes.
lowesUS <- read.csv("https://query.data.world/s/ocigglimcwicmbvzqezw6gwtzuxapk?dws=00000", header=TRUE, stringsAsFactors=FALSE)
lowesUS <- lowesUS %>% filter(state == "CA")


ca_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 = LuckyUS, 
                   lat = LuckyUS$latitude,
                   lng = LuckyUS$longitude,
                   popup = LuckyUS$name,
                   weight = 1,
                   radius=4,
                   color = "red", 
                   opacity = 1) %>% 
  addCircleMarkers(data = lowesUS, 
                   lat = lowesUS$latitude,
                   lng = lowesUS$longitude,
                   popup = lowesUS$name,
                   weight = 1,
                   radius=4,
                   color = "blue", 
                   opacity = 1)
lowesUS <- read.csv("https://query.data.world/s/ocigglimcwicmbvzqezw6gwtzuxapk?dws=00000", header=TRUE, stringsAsFactors=FALSE)
lowesUS <- lowesUS %>% filter(state == "CA")

# Define custom icons
customIcon <- makeIcon(
  iconUrl = "https://dynl.mktgcdn.com/p/jOufL-m80j0MUjs-k57WtCqKN_XSLouJm_eMiILm0RU/400x227.png",
  iconWidth = 20,
  iconHeight = 20
)

lowesUSIcon <- makeIcon(
  iconUrl = "https://www.lowescdn.com/images/logos/LowesLogo_RGB.png",
  iconWidth = 20,
  iconHeight = 20
)

ca_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
  ) %>%
  addMarkers(
    data = LuckyUS,
    lat = LuckyUS$latitude,
    lng = LuckyUS$longitude,
    popup = LuckyUS$name,
    icon = customIcon
  ) %>%
  addMarkers(
    data = lowesUS,
    lat = lowesUS$latitude,
    lng = lowesUS$longitude,
    popup = lowesUS$name,
    icon = lowesUSIcon
  )

Insight Map 3

  1. Population Targeting: Lucky Supermarkets and Lowe’s appear to have distinct targeting strategies based on population density. Lucky Supermarkets concentrate their stores in densely populated areas (darker green) where there’s a larger potential customer base, likely focusing on convenience shopping needs. In contrast, Lowe’s has a wider presence across the state, including areas with lower population density (lighter green). This suggests Lowe’s might target customers willing to travel further for a broader selection of hardware supplies or cater to suburban and rural demographics with home improvement needs.

  2. Potential Overlap and Competition: While the stores seem to have different primary target areas, there is some overlap, particularly in moderately populated areas (medium green). This overlap indicates potential competition between Lucky Supermarkets and Lowe’s for customers who might be looking for products that both stores carry, like household essentials or gardening./ supplies.

Insights about Color Choice

  1. Population Density Color: Green is often used to show where more or fewer people live in an area. Dark green shows where lots of people live and light green shows places with fewer people. This makes sense when looking at the map, making it easy to understand.
  2. Using red circles for Lucky and blue circles for Lowes makes it clear where each company’s locations are on the map. The matching colors let you easily see which dots represent Lucky stores and which ones are Lowes.
  3. Including the Lucky and Lowes logos on the map helps someone looking at this data quickly identify where the different companies have stores located across California. The images connect the dots on the map to the actual store brands.
# Define custom icon
customIcon <- makeIcon(
  iconUrl = "https://dynl.mktgcdn.com/p/jOufL-m80j0MUjs-k57WtCqKN_XSLouJm_eMiILm0RU/400x227.png",
  iconWidth = 20,
  iconHeight = 20
)

# Function to create popup with count
popupCount <- function(cluster) {
  div(
    paste("Number of Lucky Supermarkets:", length(cluster))
  )
}

# Create map
leaflet() %>% 
  setView(lng = -119.4179, lat = 36.7783, zoom = 6) %>%  # Set coordinates for California
  addProviderTiles(provider = "Esri.WorldStreetMap") %>%
  addCircleMarkers(data = LuckyUS, 
                   lat = ~latitude, 
                   lng = ~longitude,
                   popup = popupCount,
                   clusterOptions = markerClusterOptions())
lowesUS <- read.csv("https://query.data.world/s/ocigglimcwicmbvzqezw6gwtzuxapk?dws=00000", header=TRUE, stringsAsFactors=FALSE)
lowesUS <- lowesUS %>% filter(state == "CA")


customIconLucky <- makeIcon(
  iconUrl = "https://dynl.mktgcdn.com/p/jOufL-m80j0MUjs-k57WtCqKN_XSLouJm_eMiILm0RU/400x227.png",
  iconWidth = 20,
  iconHeight = 20
)

customIconLowes <- makeIcon(
  iconUrl = "https://www.lowescdn.com/images/logos/LowesLogo_RGB.png",
  iconWidth = 20,
  iconHeight = 20
)

# Function to create cluster icons
clusterIconLucky <- JS(
  "function(cluster) {
     var childCount = cluster.getChildCount();
     var className = 'marker-cluster';
     return new L.DivIcon({
       html: '<div style=\"background-color: red;\"><span style=\"color: black;\">' + childCount + '</span></div>',
       className: className,
       iconSize: new L.Point(40, 40)
     });
   }"
)

clusterIconLowes <- JS(
  "function(cluster) {
     var childCount = cluster.getChildCount();
     var className = 'marker-cluster';
     return new L.DivIcon({
       html: '<div style=\"background-color: blue;\"><span style=\"color: black;\">' + childCount + '</span></div>',
       className: className,
       iconSize: new L.Point(40, 40)
     });
   }"
)

# Create leaflet map
leaflet() %>% 
  setView(lng = -119.4179, lat = 36.7783, zoom = 6) %>%  # Set coordinates for California
  addProviderTiles(provider = "Esri.WorldStreetMap") %>%
  addCircleMarkers(data = LuckyUS, 
                   lat = ~latitude, 
                   lng = ~longitude,
                   popup = ~name,
                   clusterOptions = markerClusterOptions(iconCreateFunction = clusterIconLucky)
  ) %>%
  addCircleMarkers(data = lowesUS, 
                   lat = ~latitude, 
                   lng = ~longitude,
                   popup = ~name,
                   clusterOptions = markerClusterOptions(iconCreateFunction = clusterIconLowes)
  )

Feedback Review

After my presentation in class, I received positive feedback on the use of images to identify the locations of Lucky’s and Lowe’s stores. It was also helpful to see how my classmates understood the point I wanted to make with my maps. While I didn’t receive many suggestions for changes, I found Xavi’s idea of implementing clustering interesting. I’ve decided to try it out and incorporate clustering into my maps. This should provide a better understanding of how Lucky’s Supermarkets and Lowe’s are distributed across California.