Customizing choropleth maps using tmap or ggplot

Hello! I’m following the text in the R Handbook on GIS, specifically about choropleth maps here and I have a few questions:

  1. 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.

  2. 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:

image image

Regards,
Ian

1 Like

Hi @neale,

Is there anyone with expertise in GIS that can help Ian with this?

All the best,

Tim

@chris @aspina @meenakshi.kushwaha @avaughan

1 Like

Hey Ian,

This book is really helpful for everything tmap related. Elegant and informative maps with tmap

  1. 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.

  1. I assume you’re using tm_text for labelling.
    Here’s the help file for it and you can see there are a lot of options. tm_text: Add text labels in tmap: Thematic Maps

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.

3 Likes

hey Ian - in addition to Chris’s tmap option above this walkthrough with {ggplot} and {ggrepel} might be helpful too

2 Likes

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:

image

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?

Regards,
Ian

1 Like

Thanks Alex! This looks like a comprehensive template, I’ll look into it as well!

Regards,
Ian

1 Like