-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
Hello
I am trying to use interactive tmaps (tmap_mode("view")) with multiple tm_bubbles layer on top of one another. It keeps on showing the latest (added last) layer only. Take this example:
library(sf)
library(tmap)
# --- Two simple horizontal lines that span the globe (near ±50° latitude) ---
lon_seq <- seq(-170, 170, by = 10)
coords1 <- cbind(lon_seq, rep(50, length(lon_seq))) # light blue line (north)
coords2 <- cbind(lon_seq, rep(-50, length(lon_seq))) # dark blue line (south)
line1 <- st_sf(id = 1L, geometry = st_sfc(st_linestring(coords1), crs = 4326))
line2 <- st_sf(id = 2L, geometry = st_sfc(st_linestring(coords2), crs = 4326))
# --- Points spread across the world ---
lon = c(-150, -90, -30, 30, 90, 150)
pts1 <- st_as_sf(data.frame(lon,lat=-20), coords = c("lon", "lat"), crs = 4326)
pts2 <- st_as_sf(data.frame(lon,lat=+20), coords = c("lon", "lat"), crs = 4326)
# --- Compose the map: lines + bubbles ---
tmap_mode("view")
map <- tm_basemap("OpenStreetMap") +
tm_shape(line1) + tm_lines(col = "lightblue", lwd = 6) +
tm_shape(line2) + tm_lines(col = "darkblue", lwd = 6) +
tm_shape(pts1) + tm_bubbles(size = 5, fill = "lightcoral", col = "lightcoral", fill_alpha = 0.5) + # first bubble layer
tm_shape(pts2) + tm_bubbles(size = 5, fill = "red4", col = "red4", fill_alpha = 0.5)
map
in which I am trying to have two lines and two bubble layers. The lines work perfectly fine, but of the two bubble layers, only one (pts2) is shown.
Have I done something wrong or is it a tmap-issue? tm_dots and tm_symbols show the same behaviour.
Thank you very much for all your contributions! I really appreciate it. I am looking forward to using tm_bubbles()!
Metadata
Metadata
Assignees
Labels
No labels