library(tidyverse)
library(tidytuesdayR)
library(leaflet)
The following blog post is a very simple visualization using the data from tidytuesday 2023, week 41. This visualization uses the leaflet library to produce a very simple spatial analysis of the ‘haunted’ locations found in Los Angeles, CA.
We begin by loading the data from the tidytuesdayR package.
<- tt_load(2023, 41) datas
Downloading file 1 of 1: `haunted_places.csv`
<- datas$haunted_places data
Next we take a glimpse of the data to see what we are working with.
glimpse(data)
Rows: 10,992
Columns: 10
$ city <chr> "Ada", "Addison", "Adrian", "Adrian", "Albion", "Albion…
$ country <chr> "United States", "United States", "United States", "Uni…
$ description <chr> "Ada witch - Sometimes you can see a misty blue figure …
$ location <chr> "Ada Cemetery", "North Adams Rd.", "Ghost Trestle", "Si…
$ state <chr> "Michigan", "Michigan", "Michigan", "Michigan", "Michig…
$ state_abbrev <chr> "MI", "MI", "MI", "MI", "MI", "MI", "MI", "MI", "MI", "…
$ longitude <dbl> -85.50489, -84.38184, -84.03566, -84.01757, -84.74518, …
$ latitude <dbl> 42.96211, 41.97142, 41.90454, 41.90571, 42.24401, 42.23…
$ city_longitude <dbl> -85.49548, -84.34717, -84.03717, -84.03717, -84.75303, …
$ city_latitude <dbl> 42.96073, 41.98643, 41.89755, 41.89755, 42.24310, 42.24…
We next subset the data for the observations found in Los Angeles, CA. The longitude and latitude are then used to plot the locations on a map using the leaflet library. The ‘J.F.K. Library Third’ location is removed from the data as it is an outlier and is not located in Los Angeles, CA.
|>
data filter(city %in% c('Los Angeles')) |>
filter(state_abbrev == 'CA') |>
filter(location != 'J.F.K. Library Third') |>
mutate(label = glue::glue('<b>{location}</b> <br> {description}')) |>
leaflet() |>
addTiles() |>
addMarkers(
lng = ~ longitude,
lat = ~ latitude,
popup = ~ label
)
Reuse
Citation
BibTeX citation:
@online{luu2023,
author = {Luu, Michael},
title = {Haunted {Los} {Angeles} - {Interactive} {Mapping} Using
{Leaflet}},
date = {2023-11-21},
langid = {en}
}
For attribution, please cite this work as:
Luu, Michael. 2023. “Haunted Los Angeles - Interactive Mapping
Using Leaflet.” November 21, 2023.