Choropleth map in ggplot with polygons that have holes

后端 未结 4 533
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 05:17

I\'m trying to draw a choropleth map of Germany showing poverty rate by state (inspired by this question).

The problem is that some of the states (Berlin, for examp

4条回答
  •  -上瘾入骨i
    2020-11-30 05:42

    Alternatively you could create that map using rworldmap.

    library(rworldmap)
    library(RColorBrewer)
    library(rgdal)
    
    map <- readOGR(dsn=".", layer="germany3")
    pov <- read.csv("gerpoverty.csv")
    
    #join data to the map
    sPDF <- joinData2Map(pov,nameMap='map',nameJoinIDMap='VARNAME_1',nameJoinColumnData='Id1')
    
    #default map
    #mapPolys(sPDF,nameColumnToPlot='poverty')
    
    colours=brewer.pal(5,"OrRd")
    mapParams <- mapPolys( sPDF
                          ,nameColumnToPlot='poverty'
                          ,catMethod="pretty"
                          ,numCats=5
                          ,colourPalette=colours
                          ,addLegend=FALSE )
    
    
    do.call( addMapLegend, c( mapParams
                              , legendLabels="all"
                              , legendWidth=0.5
                            ))
    
    #to test state names
    #text(pov$x,pov$y,labels=pov$Id1)
    

    German poverty map created using rworldmap

提交回复
热议问题