Create colour Grid over map in R

2.3k Views Asked by At

I have been trying to create a grid over my world map in such a way as shown below example of gridded map

I want to be able to colour the grid based on the rate2 column in my file. Most of the solutions I have gotten only colour the world based on countries. Please how may I go about this. I have attached my csv.

heatmap.csv

1

There are 1 best solutions below

0
On

Take a look at some of the spatial interpolation packages in R, the Spatial Task View for R provides a nice list, e.g. automap, gstat, Fields, geoR etc. To get a map you need to:

  • Define a prediction grid
  • If needed, fit some mathematical properties of the data, e.g. a variogram in case of kriging.
  • Predicting the values onto this new grid.

I think for this data your first best bet are some inverse distance weighted, or spline based interpolation (e.g. Tps in Fields).

Some notes:

  • Your data is only on land, I would recommend only defining the prediction grid on land.
  • You have more than one observations at the same spatial location. I know for sure that the kriging implementation in automap/gstat will not like this. Either throw away, or aggregate (e.g. mean) the duplicate observations. There are ways of using the duplicates to estimate the measurement uncertainty and takes this into account during interpolating, but this is not trivial to implement.

See also two of my previous posts on the topic for more information: