本文介绍了使用PBSMapping和Shapefile帮助在R中绘制地理数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

O'Reilly的R中的数据混搭为灵感,我试图绘制一些在犹他州盐湖县shapefile上找到的地址此处.

Using O'Reilly's Data Mashups in R as inspiration, I'm trying to plot a handful of addresses on a shapefile of Salt Lake County, Utah found here.

我有数据框geoTable:

I have data frame geoTable:

> geoTable
         address        Y         X EID
1    130 E 300 S 40.76271 -111.8872   1
2    875 E 900 S 40.74992 -111.8660   2
3   2200 S 700 E 40.72298 -111.8714   3
4    702 E 100 S 40.76705 -111.8707   4
5 177 East 200 S 40.76518 -111.8859   5
6    702 3rd ave 40.77264 -111.8683   6
7   2175 S 900 E 40.72372 -111.8652   7
8   803 E 2100 S 40.72556 -111.8680   8

我已将其强制为一个eventData对象:

And I've coerced it into an eventData object:

> addressEvents<-as.EventData(geoTable,projection=NA)
> addressEvents
         address        Y         X EID
1    130 E 300 S 40.76271 -111.8872   1
2    875 E 900 S 40.74992 -111.8660   2
3   2200 S 700 E 40.72298 -111.8714   3
4    702 E 100 S 40.76705 -111.8707   4
5 177 East 200 S 40.76518 -111.8859   5
6    702 3rd ave 40.77264 -111.8683   6
7   2175 S 900 E 40.72372 -111.8652   7
8   803 E 2100 S 40.72556 -111.8680   8

因此,看起来我已经具备了所有需要绘制的内容,但无法正常工作.当我加载shapefile并使用

So it looks like I've got everything I need to plot-but its not working. When I load the shapefile and plot using

addPoints(addressEvents,col="red",cex=.5)

我只剩下一个空的shapefile.另外,当我尝试对eventData对象运行findPolys时,它返回NULL.

I'm left looking at an empty shapefile. Additionally, when I try and run findPolys against my eventData object, it returns NULL.

> findPolys(addressEvents,myShapeFile)
NULL

我该如何进行这项工作?我能够顺利完成O'Reilly教程,并且很难弄清楚我在哪里出错了.我不知道它是shapefile,数据框还是其他文件.

How can I make this work? I was able to complete the O'Reilly tutorial without any problems and am having difficulty figuring out where I'm going wrong here. I dont know if its the shapefile, my data frame, or whateverelse.

这是我用来导入数据和shapefile的命令

Here are the commands I use to import my data and shapefile

slc<-read.table('~/utah.txt',sep=',',header=TRUE,strip.white=TRUE,stringsAsFactors=FALSE)

myShapeFile<-importShapefile("/Users/neil/Downloads/SGID93_DEMOGRAPHIC_CensusTracts2000/SGID93_DEMOGRAPHIC_CensusTracts2000",readDBF=TRUE)

推荐答案

您可能还需要查看以下相关问题,尤其是在Eduardo的答复中:

You may also want to look at these related questions, especially at Eduardo's responses:

  • plotting-color-map-with-zip-codes-in-r-or-python
  • developing-geographic-thematic-maps-with-r

这篇关于使用PBSMapping和Shapefile帮助在R中绘制地理数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 14:48