This map shows the locations of all in-state chorus members (yellow) and a center point (purple) marking the average of the member location latitudes and the average of the member location longitudes.
Click the “Layers” icon on the left, under the minus sign, to change the base map. The OpenStreetMap base may be particularly helpful for identifying where things are.
Locations of the two out-of-state chorus members were omitted, both from the map and from the center point calculations.
R code:
# Required packages
if (!require("tidyverse"))
install.packages("tidyverse")
if (!require("tidygeocoder"))
install.packages("tidygeocoder")
if (!require("sf"))
install.packages("sf")
if (!require("mapview"))
install.packages("mapview")
if (!require("leaflet"))
install.packages("leaflet")
if (!require("leaflet.extras2"))
install.packages("leaflet.extras2")
library(tidyverse)
library(tidygeocoder)
library(sf)
library(mapview)
library(leaflet)
library(leaflet.extras2)
library(leafpop)
mapviewOptions(basemaps.color.shuffle = FALSE)
# Read data
Addresses <- read_csv("TTSCAddresses.csv")
# Filtering out unusually distant addresses
LNames <- c("Nicoletta", "Reynolds")
Addresses <- Addresses %>%
filter(!(Last %in% LNames))
# Geocoding data
# Note: Using U.S. Census Bureau geocoding API
# Note: Substituted Culleoka, TN, post office address
# for a Culleoka P.0. box that was not geocodable
Addresses <- Addresses %>%
geocode(Address, method = "census")
# Making the map
MapData <- st_as_sf(Addresses,
coords = c("long", "lat"),
crs = 4326)
MyMap <- mapview(MapData,
layer.name = "Member",
popup = popupTable(
MapData,
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("Last")))
# Showing the map
MyMap
# Calculating centroid by averaging
# latitude and longitude coordinates
long <- mean(Addresses$long)
lat <- mean(Addresses$lat)
Addresses_C <- Addresses %>%
add_row(Address = "Center",
long = long,
lat = lat) %>%
mutate(Point = case_when(Address == "Center" ~ "Center",
TRUE ~ "Member"))
# Making a map with the centroid
MapData2 <- st_as_sf(Addresses_C,
coords = c("long", "lat"),
crs = 4326)
MyMap2 <- mapview(MapData2,
zcol = "Point",
layer.name = "Point type",
popup = popupTable(MapData2,
feature.id = FALSE,
row.numbers = FALSE,
zcol = c("Last")))
# Showing the map with the centroid
MyMap2