'How to change legend of tm_bubble ( Tmap)
I created a map that has only has a value of 1 in the column "labour". The issue I am getting is that the legend shows up as in 0.2 scale. How do I make sure only the one bubble (1.0 bubble) shows up in the legends but as the smallest size in the range?
this is the code I used
library(tmap)
tmap_mode("plot")
v11<-tm_shape(GEWEsettingmap)+
tm_polygons("Construction", palette= "Reds",
colorNA="white",
showNA=FALSE)+
tm_shape(GEWEsettingmap)+
tm_bubbles(size="Labour",col="blue")+
tm_shape(GEWEsettingmap)+
tm_bubbles(size="Capital",col="yellow")+
tm_shape(worldmap2) +
tm_borders(col = "grey",lwd = 0.5)+
tm_layout(bg.color = "white")+
tm_layout(frame = TRUE,outer.margins=c(.05,0,.05,0), inner.margins=c(0,0,.02,0), asp=0,
legend.outside=TRUE,
legend.position=c("right","bottom"),
title.position = c('right','top'))
# legend.stack = "horizontal")
v11
I replaced the tm_bubble of labour in hopes to get what I wanted but I got an error:
tm_bubbles(size="Capital",col="yellow",
style="fixed",
breaks=c(1),
labels(1))
Error: symbol shape(s) ('shape' argument) is/are neither numeric nor valid variable name(s)
Solution 1:[1]
In your second code block, you didn't name the labels argument but used a labels() function instead, which was passed on to the next argument in the list, shape (the argument used to define what symbol is used to mark a point).
The first thing to do would be to try with the proper argument name:
tm_bubbles(size = "Capital", col = "yellow",
style = "fixed",
breaks = 1,
labels = 1)
However, to work with tm_bubbles(), I believe you should use the arguments sizes.legend (and sizes.legend.labels if at all needed) for customizing it. For example:
tm_bubbles(size = "labour", col = "yellow",
style = "fixed",
sizes.legend = 1)
This would only show the bubble size for 1, and label it with "1".
You can also make it automatically use all the unique values present in the dataset by using something like unique(GEWEsettingmap$Capital).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stragu |

