私は各地域で達成された年間売上高を表示するためにクライアントが定義した販売地域の地図を作成しようとしています。ZCTAの境界をマージして郵便番号に基づいてユーザー定義の地域を取得するR
私はセンサスcb_2015_us_zcta510_500k.zipからZCTAファイルをダウンロードしました。私は、領土のマップを取得するには、次のコードを使用:
en`#reading shapefile
oregon <- readOGR(dsn = ".", layer = "cb_2013_us_zcta510_500k")
#alignment data from hive, this is the file that have zip codes corresponding to all the territories
Territory_Zip_dataunique_zip <- dataTier1
Territory_Zip_dataunique_zip$l_alignment.zipcode <- clean.zipcodes(Territory_Zip_dataunique_zip$l_alignment.zipcode)
terrData <- Territory_zip_data_unique_zip
#Get all the zip codes from my territory file
terrData1 <- data.frame(Territory_zip_data_master[,1])
names(terrData1) <- c("GEOID10")
#Subset ZCTA file to have only zips that are in my territory file
oregonSubset <- merge(oregon,terrData1, all.y = F, all.x = F)
#merge with territory file to get corresponsding territory ids
natnds <- merge(oregonSubset, terrData, by.x = "GEOID10", by.y = "l_alignment.zipcode", all.y = F, all.x = F)
#make territory ids as revised ids for polygondataframe
revised_id <- natnds$l_alignment.territoryid
#Redefine shapefile based on revised ids
unionPoly <- unionSpatialPolygons(oregonSubset,revised_id)
#Fortify the spacialpolygondataframe
unionPoly_fort <- fortify(unionPoly)
#Plot
p <- ggplot() +
geom_polygon(data = ds, aes(x = long, y = lat, group = group,
fill = id), color = "black", size = 0.25) +
theme(legend.position="none",
plot.background = element_rect(fill = "transparent",colour = NA),
panel.background =element_rect(fill = "transparent",colour = NA), # or theme_blank()
panel.grid.minor =element_blank(),
panel.grid.major =element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank())
私は次の出力
が今、問題は、左側のギャップ(間に空白)で取得しますチャート。こうしたギャップのない色でいっぱいの連続した領土境界を得るにはどうすればよいですか?言い換えれば、私は何とかチャートの右の部分のようにすることができますか?
私はそれがデータの問題であることを理解していますが、それらのギャップには郵便番号が定義されていないので、元のシェイプファイルをプロットすることでわかります。
誰もこのギャップを埋もれようとしましたか?