Hello! I’m following the text in the R Handbook on GIS, specifically about choropleth maps here and I have a few questions:
Is there a way to customize the legend title in tmap? For example, changing “cases_10kpop” to “Cases per 10,000 pop.”? For ggplot, I can use labs(fill = “Cases per 10,000 pop.”) but it doesn’t seem to work with tmap.
Is it possible to customize the admin unit labels such as moving it to a different place rather than being at the centroid? In small geographic areas, the labels tend to overlap, such as in the following:
Yes you can change the legend title. It’s a different syntax as tmap is different from ggplot2.
Assuming you’re using tm_polygons for your choropleth then you’d do something like this.
tm_shape(Data) +
tm_polygons("cases", title="Cases per 10,000 pop") +
Data is your spatial data frame. Cases is the variable you’re plotting and the title argument allows you to change what’s in the legend.
You could try setting remove_overlap = TRUE in the tm_text and see if that helps with getting rid of the overlaps. Otherwise there is an argument called auto.placement but I think that’s a bit tricky to use for what you want.
Hi Chris! Thank you for your response! Both solutions worked great. I was able to change the legend title with tm_polygons(title=“title here”). I also got auto.placement to work somehow with the following result:
Is it also possible to add a line from the centroid of the polygon to the actual polygon label (placed by tm_text)? That way, the label can be placed further from the polygon but stil point towards it?