tmap icon indicating copy to clipboard operation
tmap copied to clipboard

tm_add_legend in interactive mode

Open WimMertens opened this issue 5 years ago • 1 comments

Hi,

Can one use tm_add_legend with type = "line" in interactive mode? For me it does not seem to work. For type = "fill" it works perfectly:

`library("sf") library("tmap") library(spData)

belgium <- world[world$name_long == "Belgium", ] tmap_mode('plot') tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + tm_add_legend(type = "line", col ="red", lwd = 2, labels = "border")

tmap_mode('view') tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + tm_add_legend(type = "line", col ="red", lwd = 2, labels = "border") tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + tm_add_legend(type = "fill", col ="red", labels = "border")`

Wim

WimMertens avatar Jul 28 '20 14:07 WimMertens

Legend types other the fill (also used for polygons and raster colors) are not implemented in leaflet. I am also waiting a while for this to happen...

mtennekes avatar Aug 12 '20 12:08 mtennekes

Works in tmap v4:

library(sf)
library(tmap)
library(spData)   

belgium <- world[world$name_long == "Belgium", ]
tmap_mode('plot')
tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + 
        tm_add_legend(type = "lines", col ="red", lwd = 2, labels = "border")

tmap_mode('view')
tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + 
        tm_add_legend(type = "lines", col ="red", lwd = 2, labels = "border")
tm_shape(belgium) + tm_borders(col ="red", lwd = 2) + 
        tm_add_legend(type = "polygons", col ="red", labels = "border")

Nowosad avatar Sep 18 '23 08:09 Nowosad