1

我希望这不是一个基本问题,我很难找到将 R 与 shapefile 结合使用的在线资源。我有一个德克萨斯州 5 位邮政编码的 shapefile,特别是本页底部的那个。

我正在加载邮政编码数据并将其绘制为:

> library(maptools)       
> zipData <- readShapePoly('~/Documents/Shapefiles/zipCodesTX/tl_2009_48_zcta5.shp')
> plot(zipData)

但是,这会产生德克萨斯州的完整地图。我想把它减少到达拉斯。

我考虑过使用zipData@bbox来找到最大值并使用xlimylim从那里缩小它,但是,这会导致 y 和 x 轴具有不同的数量。

> zipData@bbox
     min       max
x -106.64565 -93.50844
y   25.83723  36.99566
> plot(zipData, xlim <- c(-100, -95))
Error in xy.coords(x, y, xlabel, ylabel, log) : 
'x' and 'y' lengths differ

有没有人知道一个简单的方法来做到这一点?

进一步的基本 shapeplot 问题:实际上如何plot()绘制我的 shapefile?names(zipData)将数据框列的名称显示为:

> names(zipData)
[1] "ZCTA5CE"  "CLASSFP"  "MTFCC"    "FUNCSTAT"
[5] "ALAND"    "AWATER"   "INTPTLAT" "INTPTLON"

显然,INTPTLAT并且INTPTLON是经纬度坐标,但将它们绘制为:

> plot(zipData$INTPTLAT, zipData$INTPTLON)

产生一个大黑盒子。plot()使用shapefile生成的地图究竟如何?

如果这些问题非常基础,我深表歉意,我只是找不到好的资源或对此的解释。

4

2 回答 2

3

xlim您可以使用函数的和ylim参数更改绘图的限制plot

library("rgdal")
shp <- readOGR("tl_2009_48_zcta5.shp", "tl_2009_48_zcta5")
plot(shp, xlim=c(-97.13, -96.47), ylim=c(32.47, 33.08), col="orange")

plot_zoom

或者您可以子集shp(类的对象SpatialPolygonsDataFrame):

zip_dallas <- c(75019, 75039, 75043, 75048, 75050, 75051, 75060, 75062, 75081,
                75089, 75098, 75104, 75125, 75134, 75141, 75146, 75149, 75154,
                75159, 75172, 75181, 75182, 75217, 75232, 75241, 75247, 75253,
                75001, 75006, 75248, 75254, 75180, 75007, 75234, 75287, 75115,
                75137, 75249, 75211, 75063, 75067, 75041, 75052, 75061, 75080,
                75088, 75116, 75150, 75201, 75202, 75203, 75204, 75205, 75206,
                75207, 75208, 75209, 75210, 75212, 75214, 75215, 75216, 75218,
                75219, 75220, 75223, 75224, 75225, 75226, 75227, 75228, 75229,
                75230, 75231, 75233, 75235, 75236, 75237, 75238, 75240, 75243,
                75244, 75246, 75251, 75252, 75270, 75040, 75042, 75044, 75038,
                75082, 76051)
ind <- x[["ZCTA5CE"]] %in% zip_dallas
plot(x[ind, ], col="orange")

plot_subset

Applied Spatial Data Analysis with R是 R 基本用法和高级空间统计的良好参考。

于 2013-11-29T10:44:11.347 回答
1

里面的问题真的太多了。

首先,阅读 R 空间任务视图以获取 R 中空间数据的信息。

然后可以阅读我对 R 中空间数据的介绍:http: //www.maths.lancs.ac.uk/~rowlings/Teaching/UseR2012/introductionTalk.html

然后注意你<-在应该使用的时候使用了=

plot(zipData, xlim <- c(-100, -95))
于 2013-11-29T09:13:22.003 回答