Tmap: legend.format not functional within tm_add_legend (?)

Created on 29 Nov 2018  路  4Comments  路  Source: mtennekes/tmap

Hi Martijn,

Love the package, it's been incredibly useful.

I'm encountering a problem with custom legends. When adding a legend with tm_add_legend(), the legend.format = list() argument doesn't seem to actually affect the printed legend, although no errors come up. I was unable to find any examples of using 'legend.format' within "tm_add_legend()' so I could just be missing something.

Minrep (stealing your code from a different issue):

data(World)
qtm(World, fill = "HPI") + 
  tm_add_legend("fill", 
                labels = letters[1:5], 
                col = rainbow(5), 
                title = "My Legend",
                legend.format = list(legend.frame = "black", legend.bg.color = "green"))

gives me:
image

bug question

Most helpful comment

@mtennekes Maybe it is a good idea to remove the legend.format argument?

All 4 comments

To be honest, I don't know why I added legend.format to tm_add_legend, because legend format options are specific per map, not per legend.

qtm(World, fill = "HPI") + 
    tm_add_legend("fill", 
                  labels = letters[1:5], 
                  col = rainbow(5), 
                  title = "My Legend") +
    tm_legend(frame = "black", bg.color = "green")

image

Oops, thanks. I should've tried that to begin with!

@mtennekes Maybe it is a good idea to remove the legend.format argument?

Well, turns out that legend.format has a different purpose, namely the styling of the legend labels (e.g. legend.format = list(text.align = "right")), rather than its layout. So the documentation was wrong:-) It's fixed now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MatthieuStigler picture MatthieuStigler  路  3Comments

Si-Chong picture Si-Chong  路  4Comments

jannes-m picture jannes-m  路  5Comments

robsalasco picture robsalasco  路  4Comments

loreabad6 picture loreabad6  路  5Comments