library(tidyverse)
library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(questionr)
library(viridis)
library(leaflet)
library(tidycensus)Lab 7
Lowes and Population Overlay
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)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.