我想将包含多边形的shapefile添加到我使用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 :(得分: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")`