我正在嘗試製作由我的客戶定義的銷售區域的地圖,以顯示在每個區域中實現的年度銷售額。合併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())
我得到以下輸出現在
,問題是在左側的空白(以之間的空白)圖表。我怎樣才能在沒有這些差距的情況下獲得充滿色彩的連續疆域邊界?換句話說,我能以某種方式使它像圖表的正確部分一樣嗎?
我知道這是數據問題,對於那些空白處沒有定義的郵政編碼,我可以通過繪製原始shapefile來查看。
有沒有人試圖彌合這些差距?