How to fill map boundaries with external images?

倖福魔咒の 提交于 2021-01-28 02:30:32

问题


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.

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?


回答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



来源:https://stackoverflow.com/questions/64318505/how-to-fill-map-boundaries-with-external-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!