0

我想将包含多边形的 shapefile 添加到我使用 Choropleth 包创建的 choropleth 地图中。使用以下代码创建了等值线图:

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 和黄金地图

提前致谢!

4

1 回答 1

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")`
于 2016-03-11T17:45:34.723 回答