tmap
tmap copied to clipboard
Setting position with numbers does not work
library(spData)
library(tmap)
# works
tm_shape(nz) +
tm_polygons("Median_income") +
tm_layout(legend.position = c("left", "bottom"))
# fails
tm_shape(nz) +
tm_polygons("Median_income") +
tm_layout(legend.position = c(0.02, 0.02))
#> Error in l$position$type: $ operator is invalid for atomic vectors
I experienced the same issue when trying to set the legend position directly with numeric values in vector c(), which contradicts the documentation. However, if you are looking for a practical workaround in the meantime, I recommend using the tm_pos_in() function and its pos.h and pos.v options within the legend.position() function. From your code above:
tm_shape(nz) + tm_polygons("Median_income") + tm_layout(legend.position = tm_pos_in(pos.h = 0.02, pos.v = 0.02))