2016-11-21 8 views
0

データをグラフ化するためにchoroplethrZipを使用した郵便番号のデータセットがあります。私は州と郡レベルのデータを見ています。しかし、郵便番号は必ずしも州および郡の線に対応するとは限りません。私はreference_map = TRUEを使用しようとしましたが、それは郡の行を持たず、少し忙しいように見えます。デフォルトの参照マップを、マップの詳細の残りの部分がない状態と郡の行があるマップに変更する方法はありますか?言い換えれば、私は通りや地形を望んでいません。R:州および郡の概要choroplethrZip

私のコードは、私が使用しているデータに似たサンプルデータです。テキサスの境界の状態に関する問題を見ることができます。

#zip.regions metadata file for choroplethrZip 
data(zip.regions) 
head(zip.regions) 

#Test data file:A data.frame containing population estimates 
# for US Zip Code Tabulated Areas (ZCTAs) in 2012. 
data(df_pop_zip) 

#Create a choropleth of US Zip Codes 
zip_choropleth(df_pop_zip, 
       state_zoom="texas", 
       title="2012 Texas State ZCTA Population Estimates", 
       legend="Population", 
       reference_map = TRUE) 

#Zoom County 
dd_fips = c(48113, 48121) 
zip_choropleth(df_pop_zip, 
       county_zoom=dd_fips, 
       title="2012 Denton & Dallas ZCTA Population Estimates", 
       legend="Population", 
       reference_map = TRUE) 

TexasPlot

DentonDallasPlot

答えて

0

私はこのブログを使用してこの作業を行う方法を見つけた:ここhttp://www.arilamstein.com/blog/2015/07/02/exploring-the-demographics-of-ferguson-missouri/

は私の最終的なコードです:

library(choroplethrZip) 
library(ggplot2) 
library(choroplethr) 


#Pull in zip.regions metadata file for choroplethrZip 
data(zip.regions) 
head(zip.regions) 

#Test data file:A data.frame containing population estimates 
# for US Zip Code Tabulated Areas (ZCTAs) in 2012. 
data(df_pop_zip) 

# highlight a county 
highlight_county = function(county_fips) 
{ 
    library(choroplethrMaps) 
    data(county.map, package="choroplethrMaps", envir=environment()) 
    df = county.map[county.map$region %in% county_fips, ] 
    geom_polygon(data=df, aes(long, lat, group = group), color = "yellow", fill = NA, size = 1) 
} 

#Zoom County 
dd_fips = c(48113, 48121) 
zip_choropleth(df_pop_zip, 
       county_zoom=dd_fips, 
       title="2012 Denton & Dallas ZCTA Population Estimates", 
       legend="Population", 
       reference_map = TRUE) + 
       highlight_county(dd_fips) 

Rplot Counties

highlight_county関数を追加するだけで、うまくいきました。私は自分のデータ(一般的な人口データではなく)でテストしたところ、それもうまくいった。

関連する問題