使用O'Reilly's Data Mashups in R作爲靈感,我試圖在Salt Lake County的一個shapefile上繪製少量地址,猶他州發現here。幫助使用PBSMapping和Shapefiles繪製R中的地理數據
我有數據幀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對象:
> 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和繪圖使用
addPoints(addressEvents,col="red",cex=.5)
我留着看着一個空的shapefile。另外,當我嘗試對我的eventData對象運行findPolys時,它將返回NULL。
> findPolys(addressEvents,myShapeFile)
NULL
我該如何做這項工作?我能夠完成O'Reilly教程而沒有任何問題,並且很難弄清楚我在哪裏出錯。我不知道它的shapefile,我的數據框架還是whateverelse。
這裏有
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)
我的直覺告訴我,它不是我的數據,而其我的shapefile 。我對shapefile的概念非常陌生。當我使用O'Reilly的shapefile文件製作plotPolys時,X和Y軸看起來像是long和lat。當我使用猶他形狀文件plotPolys時,X和Y軸看起來像一個不同的編號系統。 – 2009-09-26 12:23:35
我從來沒有使用PBSmapping包。我已經與maptools輕微混淆。 – 2009-09-28 15:01:04