【问题标题】:How can I plot a SpatialPolygonDataframe variable?如何绘制 SpatialPolygonDataframe 变量?
【发布时间】:2017-11-28 23:01:57
【问题描述】:

我有一个这种类型的 SPDF:

class       : SpatialPolygonsDataFrame 
features    : 11723 
extent      : -2294145, -1102155, 2191605, 3506145  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 
variables   : 10
names       : OBJECTID,    POI_ID, PROD_UNIT, Y_Centroid, X_Centroid,   AREA, seg_id,   Avg, Lon_Centro, Lat_Centro 

当我使用plot(spdf) 绘制它时,我得到了多边形。

但我想使用其中一个变量(例如 AREA)为这些多边形着色。

我知道如何使用spplot,但我想使用 baseplot,因为它要快得多。我该怎么做?

这就是我使用spplot 的方式:

spplot(SPDF, "AREA", main = "area (m2)")

【问题讨论】:

    标签: r plot geospatial spatial raster


    【解决方案1】:

    这在基本 R 中是可能的,但不是最用户友好的。如果您将要绘制的颜色保存为数据集中的列,则最简单。

    这是一个可重现的数据集:

    library(maptools)
    setwd(system.file("shapes", package="maptools"))
    columbus <- readShapeSpatial("columbus.shp")
    plot(columbus)
    

    在这种情况下,总共有 49 个 shapefile,所以我将只分配 7 种颜色的随机调色板:

    columbus$colour <- rep(c("red", "blue", "green", "orange", "pink", "grey", "yellow"),7)
    plot(columbus, col=columbus$colour)
    

    如果您想指定颜色范围,可以在此处查看此答案:R - stuck with plot() - Colouring shapefile polygons based upon a slot value

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2023-04-04
      • 2017-08-31
      • 1970-01-01
      • 2016-12-16
      • 2012-11-30
      • 2018-11-30
      • 2020-10-05
      • 2020-09-16
      相关资源
      最近更新 更多