mapview icon indicating copy to clipboard operation
mapview copied to clipboard

mapview() mixes non-spatial tables into a single layer

Open AMBarbosa opened this issue 2 years ago • 1 comments

When trying to plot two separate non-spatial tables, mapview() seems to combine them into a single layer, and the map doesn't allow telling them apart. Here's a reproducible example using two small GBIF datasets downloaded with the 'geodata' package:

library(mapview)
library(geodata)

gbif1 <- sp_occurrence(genus = "Podarcis", species = "lilfordi", geo = TRUE)
gbif2 <- sp_occurrence(genus = "Alytes", species = "muletensis", geo = TRUE)

mapview(gbif1, xcol = "lon", ycol = "lat", col.regions = "blue", crs = "epsg:4326") +
  mapview(gbif2, xcol = "lon", ycol = "lat", col.regions = "red", crs = "epsg:4326")

The two layers are properly mapped separately if they're previously converted to spatial objects:

gbif1 <- vect(gbif1, geom = c("lon","lat"), crs = "epsg:4326")
gbif2 <- vect(gbif2, geom = c("lon","lat"), crs = "epsg:4326")

mapview(gbif1, col.regions = "blue") +
  mapview(gbif2, col.regions = "red")

Cheers!

AMBarbosa avatar Apr 07 '23 11:04 AMBarbosa

Hi, non-spatial objects are handled a bit differently and are not a high priority in general. You can set layer.name explicitly to get two distinct layers:

mapview(gbif1, xcol = "lon", ycol = "lat", col.regions = "blue", crs = "epsg:4326", layer.name = "gbif1") +
  mapview(gbif2, xcol = "lon", ycol = "lat", col.regions = "red", crs = "epsg:4326", layer.name = "gbif2")

tim-salabim avatar Apr 08 '23 09:04 tim-salabim