私は R を初めて使用し、ggplot2 を使用して郡レベルの失業データのコロプレスを複製しようとしました。FIPS コードをシェープファイルとデータの両方の間の識別変数として使用します。Hadley と Barry が何年も前に使用した方法をメッシュ化しようとしましたが ( http://blog.revolutionanalytics.com/2009/11/choropleth-challenge-result.html )、エラーが発生し続けます。Aesthetics must either be length one, or the same length as the dataProblems:freq_a
数日間、これを修正する方法を見つけようとしてきたので、助けていただければ幸いです。
これが私のコードです:
require(rgdal)
require(maps)
require(rgdal)
require(RColorBrewer)
require(ggplot2)
unem<-read.table("unemployment09.csv",sep=",",
as.is=TRUE,
colClass=c(rep("character",8),"numeric"),
col.names=c("code","f1","f2","name","yr","x1","x2","x3","percentage")
)
unem$fips=paste(unem$f1,unem$f2,sep="")
county<-readOGR("tl_2009_us_county.shp",
"tl_2009_us_county")
colClasses=c("character", "character")
county$fips<-paste(county$STATEFP,county$COUNTYFP,sep="")
m<-match(county$fips, unem$fips)
county$freq<-unem$percentage[m]
county$freq[is.na(county$freq)]=0
county$freq_a<-cut(county$freq, breaks = c(seq(0,10,by=2),35))
county$freq_a<-as.numeric(county$freq_a)
ggplot(county, aes(long, lat, group = group)) +
geom_polygon(aes(fill = county$freq_a), colour = "white", size = 0.2) +
scale_fill_brewer(palette = "PuRd") + theme(panel.background = element_rect(fill =
"white"))
ありがとう