tmap icon indicating copy to clipboard operation
tmap copied to clipboard

border.col in tm_add_legend does not take in a vector

Open xiaofanliang opened this issue 2 years ago • 2 comments

Hi tmap team,

I have the following example codes. The issue I ran into is that border.col does not take in a vector like other aesthetics variables in tm_add_legend. You can see an example output image below for the codes. You can see that the thinner/second polygon's border color did not change even though I pass in two values, while other lwd and labels are fine. I would like to have that functionality and this should be easy to change. Many thanks in advance!!

tmap_mode('plot')
data(World)
tm_shape(World) + 
  tm_polygons(alpha=0) + 
  tm_add_legend('fill', labels=c('a', 'b'), alpha=0, border.col=c('red', 'blue'), border.lwd=c(3,1))

Screen Shot 2022-03-30 at 11 14 30 PM

xiaofanliang avatar Mar 31 '22 03:03 xiaofanliang

Thanks for reporting this.

It should be a relatively easy fix, but it has low priority for me to be honest. PRs are welcome. It is this code chunk that needs to be improved: https://github.com/r-tmap/tmap/blob/master/R/plot_legend_prepare.R#L38-L60

mtennekes avatar Apr 01 '22 11:04 mtennekes

It works for symbols though

data(World)
tm_shape(World) + 
   tm_polygons(alpha=0) + 
   tm_add_legend('symbol', labels=c('a', 'b'), alpha=0, border.col=c('red', 'blue'), border.lwd=c(3,1))

image

statnmap avatar Apr 28 '22 07:04 statnmap