Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AMBarbosa opened this issue Apr 7, 2023 · 1 comment
Open

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

AMBarbosa opened this issue Apr 7, 2023 · 1 comment

Comments

@AMBarbosa
Copy link

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!

@tim-salabim
Copy link
Member

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants