2014-05-08 4 views
5

Ich habe einen SpatialPolygonsDataFrame, dass ich den folgenden Befehl ein Grundstück mit:SpatialPointsDataFrame über einen SpatialPolygonsDataFrame Plotten

spplot(milanoNILNew, "percPolVita",at = c(0,0.0696,0.08979,0.0974,0.1116,0.181),col.regions =pal,main="Quota Clienti Unipol con Polizze Vita ") 

ich einen spatialPointsDataFrame mit dem folgenden Befehl

agenziePoints<-SpatialPointsDataFrame(coords=datiAgenzie[,c("Long","Lat")],data=datiAgenzie,proj4string = llCRS, match.ID = TRUE). 

ich in der Lage bin plotten erstellt haben die Polygone, aber ich bin nicht in der Lage, agenziePoints auf den Polygonen auf demselben Diagramm darzustellen. Vielen Dank im Voraus für die Unterstützung.

Antwort

5

Verwenden Sie einfach die Basis-Plot-Funktion mit dem Argument add = TRUE.

require(sp) 

# Create polygons 
sr=SpatialPolygons(list(
    Polygons(list(Polygon(cbind(c(180114,180553,181127,181477,181294,181007,180409, 
    180162,180114),c(332349, 332057, 332342, 333250, 333558, 333676, 332618, 332413, 332349)))),"1"), 
    Polygons(list(Polygon(cbind(c(180042,180545,180553,180314,179955,179142,179437,179524,179979,180042), 
    c(332373,332026,331426,330889,330683,331133,331623,332152,332357,332373)))),"2"))) 
srdf=SpatialPolygonsDataFrame(sr, data.frame(cbind(1:2,1:2), row.names=c("1","2"))) 

# Add points (sp meuse dataset) 
data(meuse) 
coordinates(meuse) = ~x+y 

# Create a color vector for the meuse points 
color <- rep("xx", nrow([email protected])) 
    color[([email protected]$copper > 0)&([email protected]$copper <= 31)] <- "black" 
    color[([email protected]$copper > 31)] <- "red" 

# Plot polygons with points overlaid  
plot(srdf, col=c("grey","blue")) 
    plot(meuse, col=color, pch=19, add=TRUE) 

Wenn Sie wirklich die spplot Funktion nutzen wollen Sie so etwas wie dies implementiert könnte:

# spplot approach 
pts=list("sp.points", meuse, pch=19, col=color) 
    spplot(srdf, "X1", col.regions=c("grey","blue"), colorkey=FALSE, 
     sp.layout=list(pts))