Мне удалось присоединиться к county.fips в пакете карт для создания карты.
library(tidyverse)
library(readr)
library(maps)
library(sringr)
data(county.fips)
frequency_final <- dataset%>%
mutate(county_join = tolower(str_remove_all(County, " County"))) %>%
mutate(fips_join = as.integer(paste(StateFIPSCode, str_pad(CountyFipsCode,3,pad="0"),sep="")))
state<- map_data("county",dataset$State)
state2 <- state %>%
mutate(polyname = paste(region,subregion,sep=",")) %>%
left_join(county.fips, by="polyname")
state_final <- inner_join(state2, frequency_final ,by=c('fips' = 'fips_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")