2

I am creating a map of Brazil with its state boundaries, which is straight forward to achieve using ggplot2 and geom_sf.

However, this time around, instead of color filling each state with data, I want to fill each state's boundaries with an external image (png), similar to this example of the largest employer in each state.

enter image description here

I have tried a few settings of geom_image and even geom_flag to no avail (hence why I am not posting any code here).

Are there any suggestions on how to approach this problem?

zx8754
  • 52,746
  • 12
  • 114
  • 209
n1mrod
  • 43
  • 4
  • ggpattern might be what you're looking for. https://coolbutuseless.github.io/package/ggpattern/articles/pattern-image.html It'll likely take some work merging connected polygons to look like the above map. – mrhellmann Oct 12 '20 at 13:58

1 Answers1

1

You can try cartography::getPngLayer/pngLayer. These two functions takes a png as input, geotag and crop it to the shape of a given polygon and creates a rasterbrick object (as a tile) that you can manipulate and plot:

https://dieghernan.github.io/cartographyvignette#png-layer

enter image description here

dieghernan
  • 2,690
  • 8
  • 16