1

I have a data frame that looks like the following only on a much larger scale called TA_population

TA_name population population_perc
Buller 2376 28.59
Grey 4653 55.98
Clutha 1283 15.44

I am trying to create a Choropleth map with tmap with proportinal symbols where population_perc colours the area(TA_name) and then adding tm_bubbles which is the actual population.

This is the code I have got so far:

library(tmap) # plotting spatial data
library(tmaptools) # additional tools for map making

# plotting
tmap_mode("plot")

# defining breaks and labels for pop_perc  
brks1 <- c(0,0.5,1,2,5,10,20,40)
labs1 <- c("0\u20130.5","0.5\u20131","1\u20132","2\u20135","5\u201310","10\u201320","20\u201340")

tm_shape(TA_population) +
  tm_polygons(col = "population_perc", 
              palette = "Reds",
              breaks = brks1,
              labs = labs1,
              border.alpha = 0.2,
              n = 7,
              title = "Population Percentage by TA's (%)") + 
  tm_shape(TA_population) +
  tm_bubbles(size = "population",
             col = "black", 
             alpha = 1,
             title.size = "Population") +
  tm_compass(position = c("right", "top"), 
             size = 1.5, 
             show.labels = T,
             color.light = "black") +
  tm_scale_bar(position = c("right", "bottom"), 
               breaks = c(0,100,200)) +
  tm_credits("Data: Census 2018, (c) StatsNZ", 
             position=c("right", "bottom"), # placement
             size = 0.8) +
  tm_layout(bg.color = "lightcyan",
            frame = T,
            legend.position = c("left","top"), # legend position
            title = "Population Percentages of South Island TA's", 
            title.size = 1, 
            title.fontface = "bold", 
            legend.title.size = 0.8, 
            legend.text.size = 0.6)

and this is what it produces:

map

How would I go about adjusting the breaks and labels for tm_bubbles hence maybe change it to intervals like (0,25000,50000,100000,200000,400000) without them overlapping an being over top of each other. I tried to do a similar thing as I did in the tm_polygons section, however it didn't work.

  • Why not change the legend to "Population in thousands" and then you'd have "10, 20, 30, 40", with more space? – jdsimkin04 Dec 11 '21 at 16:25

1 Answers1

0

First thing that you should consider is changing the labels to thousands, as suggested above.

On top of that, a good work-around is converting the legend to portrait and inserting empty intervals between the values. This way you plot bubbles for which size is 0, which means that they aren't actually plotted. At the same time you label them with an empty string.

     tm_shape(TA_population) +
      tm_bubbles(size = "population",
                 col = "black", 
                 alpha = 1,
                 title.size = "Population", 

                 ### this specifies the legend to be in portrait mode
                 legend.size.is.portrait=TRUE, 

                 ### this specifies the breaks - bubbles of size 0 
                 ### will be plotted but won't be noticeable due to their size
                     sizes.legend=c(25000,0,100000,0,400000), 

                 ### here you label the breaks, with zeroes labeled as empty strings
                     sizes.legend.labels=c("25k","","100k","","400k")