Unexpected behavior: mapview::mapview()

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.

Hey Chris, if I understand your issue correctly, it seems to work for me (SLC points are at SLC). Are you sure you started from a fresh session?
image

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. Screenshot (6)

Here is my session info... And I really appreciate you taking some time to look at this.

> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mapview_2.7.8 dplyr_1.0.2   sf_0.9-6     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5              RColorBrewer_1.1-2      pillar_1.4.6            compiler_3.5.3         
 [5] base64enc_0.1-3         class_7.3-17            tools_3.5.3             uuid_0.1-4             
 [9] digest_0.6.27           packrat_0.5.0           jsonlite_1.7.1          viridisLite_0.3.0      
[13] satellite_1.0.2         lifecycle_0.2.0         tibble_3.0.4            lattice_0.20-41        
[17] pkgconfig_2.0.3         png_0.1-7               rlang_0.4.8             cli_2.1.0              
[21] DBI_1.1.0               rstudioapi_0.11         crosstalk_1.1.0.1       yaml_2.2.1             
[25] e1071_1.7-4             raster_3.3-13           leaflet.providers_1.9.0 systemfonts_0.3.2      
[29] gdtools_0.2.2           generics_0.1.0          vctrs_0.3.4             htmlwidgets_1.5.2      
[33] webshot_0.5.2           classInt_0.4-3          stats4_3.5.3            leaflet_2.0.3          
[37] grid_3.5.3              tidyselect_1.1.0        svglite_1.2.3.2         glue_1.4.2             
[41] R6_2.5.0                fansi_0.4.1             leafpop_0.0.6           sp_1.4-4               
[45] farver_2.0.3            purrr_0.3.4             magrittr_1.5            scales_1.1.1           
[49] codetools_0.2-16        ellipsis_0.3.1          htmltools_0.5.0         units_0.6-7            
[53] assertthat_0.2.1        colorspace_1.4-1        brew_1.0-6              KernSmooth_2.23-18     
[57] munsell_0.5.0           leafem_0.1.3            crayon_1.3.4 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.