1

I would like your help with producing a heatmap in R for rainfall in Zimbabwe. The data appended below gives the station name, latitude, longitude and predicted rainfall for 103 stations in Zimbabwe. I would like to have these plotted as a heatmap.

Here's the code I have tried so far:

library(maptools)
library(raster)
library(plyr)
library(ggplot2)
library(rgdal)

zim <- getData("GADM", country = "ZW", level = 0)

plot(zim)
points(Latitude, Longitude, cex = 1)

Your help will be much appreciated.

Many thanks,

structure(list(Station.name = c("Arcturus Post Office", "Banket Rail", 
"Beatrice Post Office", "Beit Bridge", "Bikita Agric", "Bindura Rail", 
"Binga", "Buffalo Range", "Buhera Met Office", "Bulawayo Airport", 
"Bulawayo Goetz", "Centenary", "Dalny Mine for Chakari", "Chegutu Rail", 
"Chimanimani D.A", "Chinhoyi", "Chipinge", "Chisengu", "Chisumbanje", 
"Chivhu Met", "Concession Rail", "Darwendale Rail", "Doma - Rukute", 
"Eiffel Blue", "Esigodini Agric. Inst", "Figtree Police", "Filabusi Police", 
"Fort Rixon", "Fothergill Island", "Glendale Rail", "Gokwe", 
"Guruve", "Gwanda Rail", "Gweru Thornhill", "Harare Airport", 
"Harare Belvedere", "Harare Kutsaga", "HEADLANDS RAIL", "Henderson", 
"HWANGE MAIN CAMPUS", "HWANGE RAIL", "Inyati", "KADOMA COTTON RESEARCH INST", 
"Kanyemba", "Kariba Airport", "Karoi", "Kezi", "Khami Rail", 
"Kwekwe", "LALAPANZI RAIL", "Lions Den", "Lupane", "Lusulu", 
"Macheke", "Makoholi", "Makuti", "MARONDERA R. S. IRRIG.", "MARULA MALALANGWE WEST", 
"MASVINGO MET.", "MATOPOS SANDVELD", "Mayo Police", "MBERENGWA D.A.", 
"Melfort", "MHONDORO", "MIDDLE SABI (TANGANDA)", "Mount Darwin", 
"MPHOENGS", "Msengezi Exp Farm", "Mukandi", "Murehwa", "Mutare Fire", 
"Mutoko", "Mvuma", "Mvurwi", "Nkai", "Norton", "Nyamandhlovu Rail", 
"Nyanga Experimental Station", "Nyazura Rail", "Odzi Ploice Rail", 
"Plumtree", "Raffingora / Chinomwe", "Rukomechi", "Rupike", "Rusape", 
"Rutenga Rail", "Sawmills Rail", "Selous", "Shamva D A", "Shangani Rail", 
"Shurugwi Rail", "Tashinga", "Rugare/Tengwe/Thurlaston", "Tuli Police", 
"Trelawney / West Enton", "Tsholotsho", "Umpfurudzi", "Victoria falls", 
"Vumba National Park", "Wedza", "West Nicholson", "Zaka", "Zvishavane"
), Latitude = c(31.31667, 30.38333, 30.85, 30, 31.61667, 31.31667, 
27.33333, 31.58333, 31.43333, 28.61667, 28.61667, 31.11667, 29.85, 
30.13333, 32.86667, 30.2, 32.61667, 32.88333, 32.23333, 30.88333, 
30.95, 30.55, 30.23333, 29.98333, 28.95, 28.33333, 29.28333, 
29.25, 28.66667, 31.05, 28.93333, 30.7, 29.01667, 29.85, 31.1, 
31.01667, 31.13333, 32.05, 30.96667, 26.95, 26.48333, 28.85, 
29.88333, 30.41667, 28.88333, 29.61667, 28.45, 28.45, 29.83333, 
30.18333, 30.48333, 27.8, 27.83333, 31.83333, 30.78333, 29.23333, 
31.46667, 28.08333, 30.86667, 28.46667, 32.28333, 29.91667, 31.31667, 
30.6, 32.38333, 31.58333, 27.86667, 30.31667, 32.81667, 31.78333, 
32.66667, 32.21667, 30.51667, 30.85, 28.9, 30.68333, 28.26667, 
32.73333, 32.16667, 32.4, 27.81667, 30.48333, 29.38333, 31.11667, 
32.13333, 30.75, 28.03333, 30.45, 31.56667, 29.35, 30, 28.45, 
29.66667, 29.2, 30.36667, 27.76667, 31.4, 25.83333, 32.78333, 
31.56667, 29.36667, 31.46667, 30.06667), Longitude = c(-17.78333, 
-17.4, -18.26667, -22.21667, -20.08333, -17.3, -17.61667, -21.01667, 
-19.31667, -20.01667, -20.15, -16.73333, -18.06667, -18.13333, 
-19.8, -17.36667, -20.2, -19.88333, -20.8, -19.03333, -17.4, 
-17.71667, -16.75, -18.28333, -20.35, -20.36667, -20.55, -20.01667, 
-16.7, -17.35, -18.21667, -16.65, -20.95, -19.45, -17.91667, 
-17.83333, -17.91667, -18.28333, -17.58333, -18.73333, -18.36667, 
-19.68333, -18.31667, -15.63333, -13.51667, -16.83333, -20.91667, 
-20.26667, -18.93333, -19.33333, -21.71667, -18.95, -18.06667, 
-18.15, -19.83333, -16.31667, -18.18333, -20.48333, -20.06667, 
-20.4, -17.86667, -20.48333, -17.98333, -18.31667, -20.18333, 
-16.78333, -21.21667, -17.95, -18.68333, -17.65, -18.8, -17.4, 
-19.28333, -17.03333, -19, -17.88333, -19.86667, -18.21667, -18.71667, 
-18.96667, -20.48333, -17.08333, -16.1, -20.55, -18.53333, -21.21667, 
-19.58333, -18.06667, -17.3, -19.78333, -19.66667, -16.81667, 
-17.1, -21.93333, -17.55, -19.75, -17.06667, -17.93333, -19.11667, 
-18.61667, -21.05, -20.33333, -20.31667), Predicted.rainfall = c(505.4789, 
380.1354, 425.6612, 233.6222, 601.1655, 447.3487, 475.9964, 390.8756, 
499.4801, 307.5571, 309.5475, 437.957, 386.8197, 379.3739, 605.311, 
385.6456, 565.3014, 752.5971, 387.2008, 442.506, 496.226, 359.9768, 
354.8198, 405.6273, 383.3047, 339.1076, 344.2534, 356.3742, 420.7896, 
461.2811, 405.7094, 385.4437, 339.4931, 356.1039, 406.755, 434.7895, 
404.5917, 424.4467, 429.8196, 367.2999, 374.4528, 362.8599, 404.1685, 
416.3198, 370.9722, 392.1199, 327.5813, 324.0834, 413.8912, 461.633, 
384.0285, 360.7371, 398.0818, 430.8791, 429.2881, 399.9767, 438.1612, 
385.7852, 409.216, 357.815, 428.3152, 335.2165, 404.468, 419.4921, 
314.3793, 429.7148, 336.4133, 429.3251, 759.4683, 474.4105, 459.1473, 
399.1272, 407.7235, 415.4483, 386.2814, 395.1693, 338.8468, 525.7489, 
427.1046, 449.0518, 333.6256, 377.7961, 654.4328, 297.3369, 433.1755, 
346.8126, 404.444, 407.1812, 438.322, 370.6139, 573.3871, 551.0414, 
391.9306, 250.8082, 463.2153, 333.3831, 411.6614, 395.5019, 794.0525, 
458.6049, 338.1812, 455.61, 341.1924)), class = "data.frame", row.names = c(NA, 
-103L))
Henrik
  • 65,555
  • 14
  • 143
  • 159
  • This may get you going: [Plotting contours on an irregular grid](https://stackoverflow.com/questions/19339296/plotting-contours-on-an-irregular-grid) – Henrik Jul 20 '20 at 20:56
  • You may need to define your variables of interest as matrix: `mat <- as.matrix(df[2:4])` – Chris Ruehlemann Jul 21 '20 at 03:10

0 Answers0