Reputation:
Starting with a toy example I can quickly get an interactive map in tmap
with the following code:
library(tmap)
tmap_mode("view")
data("World", "metro")
tm_shape(World) +
tm_polygons('life_exp',
legend.show = TRUE) +
tm_shape(metro) +
tm_dots("pop2010",
col = "red",
legend.show = TRUE) +
tm_format("World")
I correctly get the legend for polygons. But failed to get one for tm_dots
despite setting legend.show = TRUE
. Is there any way around it?
Upvotes: 0
Views: 1217
Reputation:
In the absence of other options, this solution might be a way around. Simply create dummy variable and map it to colour or palette of choice:
library(tmap)
tmap_mode("view")
data("World", "metro")
metro$MyLegend <- "My item"
tm_shape(World) +
tm_polygons('life_exp',
legend.show = TRUE) +
tm_shape(metro) +
tm_dots(col = "MyLegend",
palette = c("red"),
legend.show = TRUE) +
tm_format("World")
Upvotes: 1