我有美国约1500个县的奶牛数量数据。我想制作一张美国地图,各县以#cows为基础,以阴影加权。 FIPS是与县对应的分数。是否有允许我执行此操作的软件包?
cows alligators FIPS
4 0 45001
9 1 22001
3 0 51001
113 2 16001
1 0 19001
2 0 29001
## some lonely cows
df<-data.frame(cows=c("4","9","113","1","2"),
fips =c(45001, 22001, 16001,19001, 29001))
## all Fips
maps::county.fips %>%
as_tibble %>%
extract(polyname, c("region", "subregion"), "^([^,]+),([^,]+)$") ->
dfips
## some county maps & left_join
map_data("county") %>%
left_join(dfips) ->
data
## more left_join
data<-left_join(data,df)
## character cows
data$cows<-as.numeric(as.character(data$cows))
### more cows
data[["cows"]][is.na(data[["cows"]])] <- 100
## even more random cows
data$cows<-ceiling(rnorm(length(data$cows),600,200))
## map with random, fictive cows
data %>% ggplot( aes(long, lat, group = group)) +
geom_polygon(aes(fill=cows)) +
coord_map() +
theme_void() +
scale_fill_viridis_c(option = "A")+
ggtitle("Fictive random cows of the United States of America", subtitle = "“In a county near YOU!”")