tmap
tmap copied to clipboard
tm_scale_continuous displaying with interval legend with linestrings
I'm converting v3 code to v4 and can't seem to get the new tm_scale_continuous to work with linestrings in that the continuous legend color scale reverts to intervals. Example below:
# generate 20 linestrings with numeric groups:
library(sf)
set.seed(42)
lon_min <- -180
lon_max <- 180
lat_min <- -90
lat_max <- 90
create_random_line <- function() {
lon_start <- runif(1, lon_min, lon_max)
lat_start <- runif(1, lat_min, lat_max)
lon_end <- runif(1, lon_min, lon_max)
lat_end <- runif(1, lat_min, lat_max)
st_linestring(matrix(c(lon_start, lat_start, lon_end, lat_end), ncol = 2, byrow = TRUE))
}
lines <- lapply(1:20, function(x) create_random_line())
lines_sf <- st_sfc(lines, crs = 4326) # Use WGS84 (EPSG:4326)
values_df <- data.frame(value = 1:20)
lines_sf <- st_sf(values_df, geometry = lines_sf)
library(tmap)
tm_shape(lines_sf) +
tm_lines("group",
lwd=5,
tm_scale_continuous(values="brewer.spectral")) +
tm_place_legends_right()
When changing to points tm_scale_continuous
works fine (presumably as it's fill
and not col
?):
tm_shape(points_sf) +
tm_dots("value",
size=2,
tm_scale_continuous(values="brewer.spectral")) +
tm_place_legends_right()
is there a way of getting a continuous colorscale legend with col?