I want to fill voronoi polygons with colors based on a variable (z in my case). Here is the code:
library(rgdal) library(deldir) library(dplyr) library(ggplot2) library(UScensus2010) x<-c(0,55,105,165,270,65,130,155,155,225,250,295, 30,100,110,135,160,190,230,300,30,70,105,170, 210,245,300,0,85,175,300,15,60,90,90,140,210, 260,270,295,5,55,55,90,100,140,190,255,285,270) y<-c(305,310,305,310,310,260,255,265,285,280,250, 260,210,240,225,225,225,230,210,215,160,190, 190,175,160,160,170,120,135,115,110,85,90,90, 55,55,90,85,50,50,25,30,5,35,15,0,40,20,5,150) z<-c(870,793,755,690,800,800,730,728,710,780,804, 855,813,762,765,740,765,760,790,820,855,812, 773,812,827,805,840,890,820,873,875,873,865, 841,862,908,855,850,882,910,940,915,890,880, 870,880,960,890,860,830) dati<-data.frame(x,y,z) vor_pts <- SpatialPointsDataFrame(cbind(dati$x,dati$y),dati, match.ID=TRUE) SPointsDF_to_voronoi_SPolysDF <- function(sp) {
Now I have this image:

I want each polygon to be displayed in the color scale based on the value of the z variable ... how can I do this? Thanks!!!