R - 在空间多边形中着色特定国家/地区

时间:2012-12-07 10:29:30

标签: r polygons

如果空间多边形中$Name_3字段所标识的区域子集(例如,只有“Magugu”和“Nkaiti”)中的一种颜色怎么样?我玩plot()和子集 - 矢量,但没有成功。非常感谢,W

Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 2800 obs. of  14 variables:
  .. ..$ PID      : int [1:2800] 97867 97868 97869 97870 97871 97872 97873 97874 97875 97876 ...
  .. ..$ ID_0     : int [1:2800] 225 225 225 225 225 225 225 225 225 225 ...
  .. ..$ ISO      : chr [1:2800] "TZA" "TZA" "TZA" "TZA" ...
  .. ..$ NAME_0   : chr [1:2800] "Tanzania" "Tanzania" "Tanzania" "Tanzania" ...
  .. ..$ ID_1     : int [1:2800] 12 12 12 12 12 12 12 12 12 12 ...
  .. ..$ NAME_1   : chr [1:2800] "Manyara" "Manyara" "Manyara" "Manyara" ...
  .. ..$ ID_2     : int [1:2800] 52 52 52 52 52 52 52 52 52 53 ...
  .. ..$ NAME_2   : chr [1:2800] "Babati" "Babati" "Babati" "Babati" ...
  .. ..$ ID_3     : int [1:2800] 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 ...
  .. ..$ NAME_3   : chr [1:2800] "Magugu" "Mamire" "Mwada" "Nkaiti" ...
  .. ..$ NL_NAME_3: chr [1:2800] "" "" "" "" ...
  .. ..$ VARNAME_3: chr [1:2800] "" "" "" "" ...
  .. ..$ TYPE_3   : chr [1:2800] "Division" "Division" "Division" "Division" ...
  .. ..$ ENGTYPE_3: chr [1:2800] "Division" "Division" "Division" "Division" ...
  ..@ polygons   :List of 2800

1 个答案:

答案 0 :(得分:0)

基础图形plot()以与所有基础图形对象相同的方式处理颜色:向其传递颜色矢量。向量对于SpatialPolygonsDataFrame的每个元素都有一个元素,元素内容是颜色。

请参阅此问题,了解如何在基本图形中绘制颜色: Plot with conditional colors based on values in R

关于SPDF的具体应用的这个问题: https://gis.stackexchange.com/questions/36877/how-do-i-change-the-polygon-fill-color-and-border-color-for-spatialpolygons-obje