清理美国县级等值线
Cleaning up a US county level choropleth
我已经得到了一个为美国县级数据编写的等值线图,但是在绘制它时我发现它很难阅读。各县可能会变得非常拥挤并开始相互融合 - 很难分辨一个州的终点和另一个州的起点。有谁知道按县数据绘制等值线图并按州创建边界轮廓的方法?这是我到目前为止用于复制的代码:
library(ggplot2)
library(fiftystater)
library(colorplaner)
library(USAboundaries)
library(sf)
usc <- us_counties(resolution = c("low", "high"), states = NULL)
st_list = c("Alabama", "Arizona", "Arkansas", "California", "Colorado",
"Connecticut", "Delaware", "Florida", "Georgia", "Idaho", "Illinois",
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New
Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
"Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West
Virginia", "Wisconsin", "Wyoming")
plot_counties <- us_counties(states=st_list, resolution = 'high')
plot_counties$dumb <- runif(nrow(plot_counties), 1,100)
ggplot(plot_counties) + geom_sf(aes(fill=dumb)) +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
scale_fill_gradientn("Title",
colours = c('darkred', 'tomato1', 'cyan2',
'darkblue'),
values = c(0,.5,.5000001, 1)) +
theme(panel.background = element_blank(), axis.ticks = element_blank(),
axis.text = element_blank())
这是一个可能的解决方案:
plot_counties <- us_counties(states=st_list, resolution = 'high')
plot_counties$dumb <- runif(nrow(plot_counties), 1,100)
plot_states <- us_states(states=st_list, resolution = 'high')
ggplot(plot_counties) +
geom_sf(aes(fill=dumb), color=NA) +
geom_sf(data=plot_states, fill=NA, color="black", lwd=1) +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
scale_fill_gradientn("Title",
colours = c('darkred','tomato1','cyan2','darkblue'),
values = c(0,.5,.5000001, 1)) +
theme(panel.background = element_blank(), axis.ticks = element_blank(),
axis.text = element_blank())
我已经得到了一个为美国县级数据编写的等值线图,但是在绘制它时我发现它很难阅读。各县可能会变得非常拥挤并开始相互融合 - 很难分辨一个州的终点和另一个州的起点。有谁知道按县数据绘制等值线图并按州创建边界轮廓的方法?这是我到目前为止用于复制的代码:
library(ggplot2)
library(fiftystater)
library(colorplaner)
library(USAboundaries)
library(sf)
usc <- us_counties(resolution = c("low", "high"), states = NULL)
st_list = c("Alabama", "Arizona", "Arkansas", "California", "Colorado",
"Connecticut", "Delaware", "Florida", "Georgia", "Idaho", "Illinois",
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New
Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
"Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West
Virginia", "Wisconsin", "Wyoming")
plot_counties <- us_counties(states=st_list, resolution = 'high')
plot_counties$dumb <- runif(nrow(plot_counties), 1,100)
ggplot(plot_counties) + geom_sf(aes(fill=dumb)) +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
scale_fill_gradientn("Title",
colours = c('darkred', 'tomato1', 'cyan2',
'darkblue'),
values = c(0,.5,.5000001, 1)) +
theme(panel.background = element_blank(), axis.ticks = element_blank(),
axis.text = element_blank())
这是一个可能的解决方案:
plot_counties <- us_counties(states=st_list, resolution = 'high')
plot_counties$dumb <- runif(nrow(plot_counties), 1,100)
plot_states <- us_states(states=st_list, resolution = 'high')
ggplot(plot_counties) +
geom_sf(aes(fill=dumb), color=NA) +
geom_sf(data=plot_states, fill=NA, color="black", lwd=1) +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
scale_fill_gradientn("Title",
colours = c('darkred','tomato1','cyan2','darkblue'),
values = c(0,.5,.5000001, 1)) +
theme(panel.background = element_blank(), axis.ticks = element_blank(),
axis.text = element_blank())