【发布时间】:2019-04-13 23:16:34
【问题描述】:
我有一张按县划分的佐治亚州地图,其频率部分使用县名的等值连接。由于名称差异,一些县正在放弃。我需要使用 FIPS 代码而不是名称。
如何根据 FIP 代码而不是名称更改加入代码?
# Input load. Please do not change #
`dataset` = read.csv('C:/temp/input_df_df0e8484-0924-4613-9af6-2fdc4b3e67ad.csv', check.names = FALSE, encoding = "UTF-8", blank.lines.skip = FALSE);
# Original Script. Please update your script content here and once completed copy below section back to the original editing window #
library(tidyverse)
library(readr)
library(maps)
frequency_final <- dataset%>%
mutate(county_join = tolower(str_remove_all(County, " County")))
state<- map_data("county",dataset$State,)
state_final <- inner_join(state, frequency_final ,by=c('subregion' = 'county_join'))
state_base <- ggplot(data = state_final , mapping = aes(x = long, y = lat, group = subregion)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = "gray")
ditch_the_axes <- theme(
axis.text = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank()
)
state_base +
geom_polygon(aes(fill =ID), color = "white") +
geom_polygon(color = "black", fill = NA) +
theme_bw() +
ditch_the_axes +
scale_fill_gradientn(colours = rev(rainbow(7)),
breaks = c(2, 4, 10, 100, 1000, 10000),
trans = "log10")
这里有指向带有 FIP 代码的示例数据集的链接 https://drive.google.com/file/d/1GrDS8qq7sgQII3-s5EmX-8n304P1ujWa/view?usp=sharing
【问题讨论】:
-
几个与映射相关的包都有县 FIPS 代码的查找表。在
maps中,它是数据集county.fips。加入你的数据。除此之外,您最好将数据样本放在帖子中,而不是让人们需要从第三方下载未知文件