2016-03-09 51 views
0

我想添加一個包含多邊形的shapefile到我使用Choroplethr包創建的choropleth映射中。 的地區分佈圖是用下面的代碼創建:將shapefile多邊形添加到Choropleth映射(Choroplethr)

choro=county_choropleth(Change, title= "WeeklyChange", state_zoom = continental_us,reference_map = F)+ scale_fill_manual(values=c("-3"="red4","-2"="red3","-1"="red1", "0"="snow","1"="greenyellow","2"="green","3"="green3"))

plot(choro)

gold= readShapePoly("Gold") gold_df= fortify(gold) land= ggplot(data= gold_df,aes(x=long, y= lat, group=group))+ geom_polygon(colour="gold3")

plot(gold)

兩個物體看起來正常,但我不能堆疊黃金地塊上的等值線地圖。 Choropleth and gold map

在此先感謝!

回答

0

感謝Ari Lamstein幫助我。以下是添加多邊形的代碼

# Create Choropleth Map 
`choro=county_choropleth(Change, title= "WeeklyChange", 
state_zoom = continental_us,reference_map = F)+ 
scale_fill_manual(values=c("-3"="red4","-2"="red3","-1"="red1", 
"0"="snow","1"="greenyellow","2"="green","3"="green3"))` 

`#Import shapefile polygons 
gold= readShapePoly("Gold")` 

`#Create dataframe for ggplot 
gold_df= fortify(gold)` 

`#Combine Choropleth Map and shapefile dataframe 
choro+geom_polygon(data= gold_df,aes(x=long, y= lat,group=group),fill="gold3")`