I am trying to develop a simple map with bubbles representing size.
library(tmap)
data(World, metro)
example.map <- tm_shape(World)+
tm_borders()+
tm_shape(metro)+
tm_bubbles(size = "pop2010",
col = "pop2010",
palette = "-RdYlBu")
example.map
The actual map is fine, it is what I want. My problem is with the legend. In the code above there are two, I can make it one by using:
legend.col.show = FALSE
or
legend.size.show = FALSE
But then I have a legend that shows either the size or the colour. Is it possible to make a single legend show both size and colour?
I had the same question so posted an issue on the tmap Github page. The package author kindly responded, https://github.com/mtennekes/tmap/issues/208#issuecomment-392348083, and copied here for reference:
"Unfortunately, this is not possible, at least automatically. However, you can add a manual legend:
data(metro)
tm_shape(metro) +
tm_dots() +
tm_add_legend("symbol", col = c("green", "blue"), size = c(.1,.5), labels = c("Cat1", "Cat2"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With