Ich möchteR: Wie Voronoi Tesselation Farbe nach Datenwert?
- Voronoi Tesselation in R von SpatialPointDataFrame OK
- erhalten SpatialPolygonDataFrame OK
- kolorieren sie durch Werte in meiner ursprünglichen SpatialPointDataFrame HOW erstellen ???
so weit: Ich habe erstellt und Voronoi Tesselation aktualisiert, folgende: und hier aktualisiert: https://gis.stackexchange.com/questions/190917/r-voronoi-tesselation-from-long-lat-data.
Ich weiß, dass ich es durch Bibliothek färben kann ("DISMO"): https://gis.stackexchange.com/questions/136542/r-function-for-thiessen-polygons
jedoch oben mit Voronoi-Funktion in meinem voronoipolygons Ich habe nur eine Variable: "Dummy". Ich möchte jedoch mein Polygon mit der Variable "z" färben - die nicht mehr in meinem .voro-Polygon enthalten ist.
voronoipolygons = function(layer) {
require(deldir)
crds = [email protected]
z = deldir(crds[,1], crds[,2])
w = tile.list(z)
polys = vector(mode='list', length=length(w))
require(sp)
for (i in seq(along=polys)) {
pcrds = cbind(w[[i]]$x, w[[i]]$y)
pcrds = rbind(pcrds, pcrds[1,])
polys[[i]] = Polygons(list(Polygon(pcrds)), ID=as.character(i))
}
SP = SpatialPolygons(polys)
voronoi = SpatialPolygonsDataFrame(SP, data=data.frame(dummy = seq(length(SP)),
row.names=sapply(slot(SP, 'polygons'),
function(x) slot(x, 'ID'))))
}
Meine Frage ist: Wie durch "z"
Variable meine .voro
Polygone kolorieren oder/und wie direkt aufzunehmen es oben in voronoipolygons()
Funktion? Ich kann "z"
Variable [email protected]
nicht einfach hinzufügen, weil die Reihenfolge der Werte geändert wird. Meine R-Fähigkeit ist noch nicht so stark .. Vielen Dank!
Dummy-Daten:
x <- c(32.5, 32.1, 33.5, 32.2, 33.0)
y <- c(-2.2, -3.3, -2.3, -2.9, -3.0)
z <- c(1, 2, 5, 8, 4)
# make df
df<-as.data.frame(cbind(x,y,z))
coordinates(df)<- ~ x + y #make SPDF
df.voro <- voronoipolygons(df) # calculated VORONOI
require('dismo')
spplot(df.voro, "dummy") # colorize Polygons
# add z variable to newly created data
[email protected]$z<-df$z ## !!! can't use this, because this change order of values in df !!!
spplot(df.voro, "z")