r - 在 SpatialPolygonsDataFrame 上绘制 SpatialPointsDataFrame

标签 r spatial rgdal

我有一个使用以下命令绘制的 SpatialPolygonsDataFrame:

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 ")

我使用以下命令创建了一个 spatialPointsDataFrame
agenziePoints<-SpatialPointsDataFrame(coords=datiAgenzie[,c("Long","Lat")],data=datiAgenzie,proj4string = llCRS, match.ID = TRUE).

我能够绘制多边形,但我无法在同一图上的多边形上表示agenziePoints。预先感谢您的支持。

最佳答案

只需使用带有 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(meuse@data))
  color[(meuse@data$copper > 0)&(meuse@data$copper <= 31)] <- "black"
    color[(meuse@data$copper  > 31)] <- "red"

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

如果你真的想使用 spplot 函数,你可以实现这样的东西:
# 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)) 

关于r - 在 SpatialPolygonsDataFrame 上绘制 SpatialPointsDataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23547445/

相关文章:

sql - SQL Server 中几何点的中心或质心

r - 在 rstudio 中安装 rgdal 库 - 在 libgdal 中找不到 GDALAllRegister

r - CRAN 检查 rgdal 不可用于检查

r - 在 R 中栅格的每个单元格上应用函数(按位 "and")?

r - R-标签中的剪切函数,无需科学记数法,可在 ggplot2 中使用

string - 获取字符串向量元素之间的最小共享部分

r - ggplot2:在 R 中创建视觉直观的时间线

r - 使用 RODBC 保持前导零

mysql - 使用mysql在 map 上搜索点时处理聚类

sql-server - 从查询中的多边形获取空间点列表