I just ran into some unexpected behavior when visualizing aggregated spatial data with mapview::mapview(). I am hoping someone can tell me what I am missing...
# Attach pkgs
library(sf)
library(dplyr)
library(mapview)
# Import spatial dataset (Utah liquor stores)
ls <- read_sf("https://opendata.arcgis.com/datasets/61b7f10c194b4ec69d02e169db1da09a_0.geojson")
# aggregate to "CITY"
ls_cty <- ls %>%
group_by(CITY) %>%
summarise(n_stores = n(),
.groups = "drop")
# Subset SLC and plot - result is as expected
ls_cty %>%
filter(CITY == "Salt Lake City") %>%
mapview(zcol = "CITY")
# Subset Ogden and plot - result is as expected
ls_cty %>%
filter(CITY == "Ogden") %>%
mapview(zcol = "CITY")
# Subset to include both SLC and Ogden and plot - result is not as expected...
ls_cty %>%
filter(CITY %in% c("Salt Lake City", "Ogden")) %>%
mapview(zcol = "CITY")
Here the points are in the correct places (2 in Ogden and 17 in SLC) and colored correctly, however, when the cursor hovers over the points "Ogden" pops up in SLC and vise versa??? I need the popup to reflect the data associated with the point. Thanks in advance for any assistance.
Etienne, Thats interesting... I started with a fresh session ran the code, it returned the same unexpected result so I restarted and ran again (just to be sure and ) same result. In my output it appears that roughly 50% of the SLC points are tagged Ogden and one of the two Ogden points is tagged SLC. I am really confused.
Here is my session info... And I really appreciate you taking some time to look at this.