Reputation: 43
I'm trying to change the alpha value of my legend to match that of the polygon fill, however nothing seems to happen when I specify the alpha argument in tm_add_legend
. Is there something blindingly obvious that i'm missing here?
library(tmap)
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
tm_shape(nc) +
tm_polygons(col = "#326abf", border.col = "white", lwd = 2, alpha = 0.5) +
tm_add_legend(type = "fill",
alpha = 0.5,
labels = "NC",
col = "#326abf")
Upvotes: 1
Views: 744
Reputation: 23574
I am not sure how tmap exactly works in this case. But I found a workaround. I created a dummy variable called mycat
. Then, I used this variable for col
in tm_polygons()
and specify the color you are using in palette
. In this way, you do not have to use tm_add_legend()
.
library(dplyr)
library(sf)
library(tmap)
mutate(nc, mycat = "one") -> nc
tm_shape(nc) +
tm_polygons(col = "mycat",
palette = "#326abf",
border.col = "white", lwd = 2, alpha = 0.5,
title = "",
labels = "NC")
Upvotes: 3