【问题标题】:Add shapefile Polygons to Choropleth Map (Choroplethr)将 shapefile 多边形添加到 Choropleth Map (Choroplethr)
【发布时间】:2016-06-24 04:26:48
【问题描述】:

我想将包含多边形的 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 and gold map

提前致谢!

【问题讨论】:

    标签: r choropleth choroplethr


    【解决方案1】:

    感谢 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")`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 2018-09-08
      • 2015-08-29
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多