2016-03-09 50 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")`