I used data from the A&C LA: World Cafe RSVP List for Day of Check-In datasheet.Added zipcode data to practice. My goals of this file is to create a location map showing the different orgs in LA. I would also like to create a word map with data from the ‘Post it: Exercise’.
Load in packages
library(readr)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ purrr 1.0.1
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(DT) #scrollable table
library(leaflet)#Creates interactive web maps using JavaScript 'Leaflet' library
library(tidygeocoder)#Geocoding made easy
## Warning: package 'tidygeocoder' was built under R version 4.3.3
Load in data
## Rows: 69 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Organization / Affiliation
## dbl (1): Zip Code
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data <- read_csv("Data/data.csv")
## Rows: 69 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Organization / Affiliation
## dbl (1): Zip Code
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_clean <- data %>%
filter(!is.na(`Zip Code`)) %>%
mutate(`Zip Code` = as.character(`Zip Code`)) %>%
# keep only CA zip ranges 90000–96999 if you truly want just CA
filter(substr(`Zip Code`, 1, 2) %in% c("90","91","92","93","94","95","96")) %>%
mutate(country = "US") # new column
data_geo <- data_clean %>%
geocode(
postalcode = `Zip Code`, # tell tidygeocoder this is a postal code
country = country, # use the "US" column
method = "osm",
lat = latitude,
long = longitude
)
## Passing 31 addresses to the Nominatim single address geocoder
## Query completed in: 43.4 seconds
These are all of the orgs/zips included in map.
datatable(
data_geo,
options = list(
pageLength = 10, # or 25, etc.
scrollY = "400px", # vertical scroll height
scrollX = TRUE # horizontal scroll if needed
),
rownames = FALSE
)
This creates the interactive map
leaflet(data_geo) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
setView(lng = -118.25, lat = 34.05, zoom = 9) %>% # focus on LA region
addCircleMarkers(
lng = ~longitude,
lat = ~latitude,
radius = 6,
color = "#004c6d", # border color
fillColor = "#1d91c0", # fill color
stroke = TRUE,
weight = 1,
fillOpacity = 0.85,
popup = ~paste0(
"<strong>", `Organization / Affiliation`, "</strong><br>",
"Zip Code: ", `Zip Code`, "<br>",
"Country: ", country
),
label = ~`Organization / Affiliation`, # shows on hover
clusterOptions = markerClusterOptions( # cluster markers when zoomed out
spiderfyOnEveryZoom = FALSE,
showCoverageOnHover = FALSE
)
) %>%
addScaleBar(
position = "bottomleft",
options = scaleBarOptions(maxWidth = 100)
) %>%
addControl(
html = "<h4 style='margin:0; padding:4px;'>Climate & Arts Network – Los Angeles</h4>",
position = "topleft"
)