library(tidyverse)
library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(questionr)
library(viridis)
library(leaflet)
library(tidycensus)Hermes_stores
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/walmart-store-location-data
HermesUS <- read.csv("hermes_2018_11_06.csv", header=TRUE, stringsAsFactors=FALSE)CREATE MAP FOR ARKANSAS LOCATIONS
Map Hermes store locations JUST FOR in CA using leaflet package.
HermesUS <- HermesUS %>% filter(state == "CA")
HermesUS %>%
leaflet(width = "100%") %>%
addTiles() %>%
setView(-120.0, 36.0, zoom = 5) %>%
addMarkers(lat = ~latitude,
lng = ~longitude,
popup = ~name)This graph shows the state of California and plots all Hermes stores in the state. Looking at the graph there seems to be 7 stores that are clustered up in 2 groups.
ACQUIRE California 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 Hermes TO POPULATION
Let’s map the CA 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.
library(RColorBrewer)
MapPalette <- colorQuantile(palette = "RdYlBu", domain = ar_pop$estimate, n = 20)
# Define the path to the image file
iconUrl <- "/Users/carlosborjes/Desktop/Data Visualization/Hermes_logo.webp"
# Define a custom icon
myIcon <- makeIcon(
iconUrl = iconUrl,
iconWidth = 40, # Adjust the width of the icon
iconHeight = 40 # Adjust the height of the icon
)
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)) %>%
addPolygons(popup = ~NAME,
stroke = TRUE, # Enable stroke for the border
color = "gray", # Set border color to gray
weight = 1, # Set the thickness of the border
smoothFactor = 0,
fillOpacity = 0.6,
fillColor = ~ MapPalette(estimate)) %>%
addLegend("bottomright",
pal = MapPalette,
values = ~ estimate,
title = "Population Percentiles",
opacity = 1) %>%
addMarkers(
data = HermesUS,
lat = ~latitude,
lng = ~longitude,
popup = ~name,
icon = myIcon # Use the custom icon for markers
)The graph shows the state of California with the population percentiles for each county.
The 7 Hermes stores in California are marked by images of the Hermes logo.
Hermes store locations tend to be in areas with higher population density. There are Hermes stores in major metropolitan areas like Los Angeles,San Francisco, and San Diego.
This aligns with the idea that a luxury brand store like Hermes targets affluent clientele, who are more likely to be concentrated in densely populated urban areas.