2
votes

I am using tmap to make a map that will have both shape and color aesthetics. However, I am noticing strange behavior in my numeric scale for color (it is producing scales of 0 min to 10 min, 10 min to 20 min, etc.). Why is tmap returning this scale? I would like to have control over the pch of the symbols, so that A and B would specified to pch's 21 and 19 respectively, how can this be accomplished?

My example:

library(tmap) 
data(metro)
metro$new_var <- c("A","B")
metro$new_var <- factor(metro$new_var)
tm_shape(metro) +
  tm_symbols(shape="new_var", col = "pop2010") +
  tm_layout(legend.outside = TRUE, legend.outside.position = "bottom", legend.stack = "horizontal")

enter image description here

1

1 Answers

2
votes

First, the scale is not min but mln (million). Perhaps that makes more sense?

Second, as to why it chooses those categories the help explains (admittedly it could be clearer) that if multiple values are specified it will do "small multiples" by which it appears to mean a small number of categories. The default style is "pretty". You can control the number of categories by n, but pretty seems to make more or less to keep it "pretty". Try this to see the effect of n:

tm_symbols(shape = "new_var", col = "pop2010", n = 6)

To have fine control, you can make your own categorical variable. You can also make it have continuous shading (you can spread it more with the n bigger):

tm_symbols(shape = "new_var", col = "pop2010", style = "cont")

Finally, with respect to the shapes, the help says that if shape is a variable you have to tell it what you want with the shapes parameter which defaults to 21:25 explaining why you see the symbols you do. 19 and 21 look a little odd to me so I'm using an alternative, but if you want 19 and 21 you'd do the same thing substituting as needed:

tm_symbols(shape = "new_var", col = "pop2010", shapes = c(24, 25))

Good luck - that is some tricky help!