0
こんにちは、R を使用した GIS は初めてで、コロプレス マップを作成しようとしています。ggplot2 と fortify 関数を使用してコロプレス マップを正常に作成しましたが、ggplot2 を使用してマップの上にレイヤーを追加するのはそれほど簡単ではありません。代わりに、maptools を使用してコロプレス マップをプロットし、後で分析に必要なレイヤーを追加しています。私がプロットしようとしているコロプレス マップは、国勢調査区によるアレゲニー郡の失業率です。ファイルはここから入手できます: shapefile https://www.dropbox.com/s/uci5g2ekeq9niww/census%20tract%20allegheyny%202010.shp csv ファイルhttps://www.dropbox.com/s/6nq8nnxftot8iya/allegheyny%20socioeconomic% 20info.csv そして、これが私のコードです
library(rgdal)
library(RArcInfo)
library(RColorBrewer)
library(maptools)
library(maps)
library(classInt)
csv ファイルをロードしてクリーンアップし、Id2 と失業のサブセットを作成します。
data<- read.csv('allegheyny socioeconomic info.csv',dec='.',
                header=T)
data$Id2<-as.numeric(as.character(data$Id2))
data$Percent.Unemployed<-as.numeric(as.character(data$Percent.Unemployed))
names(data)[names(data)=="Percent.Unemployed"]<-'unemployed'
data1<-subset(data, select= c('Id2', 'unemployed'))
2010 年のアレゲニー郡国勢調査区のシェープファイルを読み込む
tracts<-readShapePoly("census tract allegheyny 2010.shp")
names(tracts)[names(tracts)=="GEOID10"]<-'Id2'

Id2 でデータをマージします

tr1<-merge(data1,tracts)                     
sort(tr1$Id2)
colours<-brewer.pal(5, 'Greens')
breaks<- classIntervals(tr1$unemployed, n=5, style='sd')
plot(tr1, col=colours[findInterval(tr1$unemployed, breaks, all.inside=T), axes=F])
そして、これは私が得るメッセージです:
Error in x[-1L] >= x[-n] : comparison of these types is not implemented
4

1 に答える 1

1
plot(tracts,col=colours[findInterval(tr1$unemployed, breaks$brks, all.inside=T)])

これを生成します:

あなたの質問に具体的に答えるには:

エラーの理由は、 がfindInteerval(...)2 番目の引数として数値のベクトルを取ることです。しかし

 breaks<- classIntervals(tr1$unemployed, n=5, style='sd')

'var' と 'brks' の 2 つの要素を持つリストを生成します。breaks$brksで使用する必要がありますfindInterval(...)

あなたの声明

plot(tr1, col=colours[findInterval(tr1$unemployed, breaks, all.inside=T), axes=F])

これはマップtr1ではなく、402 行のデータ フレームです。必要があるplot(tracts,...)

最後に、どうして ggplot にレイヤーを追加するのが難しいと思いますか??

于 2013-12-11T04:05:52.190 に答える