相关疑难解决方法(0)

geom_map "map_id" reference issue

I am trying to create a choropleth map of US counties with two datasets connected by FIPS codes. I am using the maps package county and county.fips data, combined into one data.table like this (probably not the most elegant way of integrating the FIPS data):

    library(ggplot2)
    library(maps)
    library(data.table)
    county <- map_data("county")    
    data(county.fips)
    county.fips <- as.data.table(county.fips)
    county.fips$polyname <- as.character(county.fips$polyname)    
    county.fips[, paste0("type", 1:2) := tstrsplit(polyname, ",")]
    names(county.fips) <- c("FIPS","polyname","region","subregion")
    county <- merge(county, county.fips, by=c("region", "subregion"), all=T)
    county <- county[,1:7]
    county <- as.data.table(county) …
Run Code Online (Sandbox Code Playgroud)

maps r ggplot2 choropleth

5
推荐指数
1
解决办法
559
查看次数

标签 统计

choropleth ×1

ggplot2 ×1

maps ×1

r ×1