My data consists of a shapefile of polygons representing municipalities in a given country. Each polygon has a population value in the shapefile's attribute table. I would like to disaggregate these values into a raster with a spatial resolution of 1 km applying a proportional allocation method. This is basically the method employed to produce the Gridded Population of the World (GPW) products.
The example below shows what I am trying to achieve (I summarized it from the GPW methods page):
In the figure below, proportional allocation has been used to distribute the value associated with each input vector polygon (left image) equally over all of the raster pixels that are completely within the polygon (right image). Values in the vector image represent the total for each polygon; values in the raster image represent the value assigned to one individual raster pixel. For example, the value 22,000 assigned to the polygon in the upper right part of the vector image is distributed equally to the pixels in the corresponding area of the raster image such that each of those pixels has a value of 98. The raster pixels that intersect multiple input polygons are assigned a value computed based on the proportion of the pixel occupied by each input polygon. Note, in the image on the right, the pixels that cross polygon boundaries have values between those of the cells on either side of the boundary that fall completely within the polygon. One such pixel has been labeled — 14 in the Southeast part of the image.
How do I solve this problem using R?