0

I want to create a piechart using tm_bubbles(), or more generally, using the tmap package in R. Here is the code I have so far:

library(tmap)
library(spData)
us_states_map = tm_shape(st_transform(us_states,2163)) + tm_polygons() + 
  tm_layout(frame = FALSE)
us_states_map + tm_shape(gbs.sf) +
  tm_bubbles(size=c("uninfected",super.haps),labels=c("uninfected",super.haps),
             col=c("gray",brewer.pal(3,"Accent")),style="cat",
             alpha=0.7,scale=2) + 
  tm_legend(legend.position=c("right","bottom"))

This creates the following plot which places each variable into a different subplot instead of plotting it proportionally into the same bubble (as seen in a piechart) in each location.

I am looking to have just one plot with each bubble representing all 4 colors in a proportional fashion instead.

PS: gbs.sf is a data matrix with the locations for each bubble, total population (here, area of the bubble), and its constituent components ("uninfected", "melissa", etc.) as a numbers.

1 Answers1

0

Please take a look at the third example from the tm_symbols help page, which does exactly that. You'll need to create a list of ggplot2 piecharts as grobs, and specify the shapes argument of tm_symbols with that.

Martijn Tennekes
  • 1,951
  • 13
  • 19