【问题标题】:Cleaning up a US county level choropleth清理美国县级合唱团
【发布时间】:2017-12-13 17:07:25
【问题描述】:

我已经为美国县级数据编写了一个等值线脚本,但在绘制它时发现它很难阅读。这些县可能会变得非常拥挤并开始相互融合——很难分辨一个州在哪里结束,另一个州从哪里开始。有谁知道按县数据绘制等值线图并按州创建边界轮廓的方法?这是我目前复制的代码:

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()) 

【问题讨论】:

    标签: r ggplot2 choropleth


    【解决方案1】:

    这是一个可能的解决方案:

    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()) 
    

    【讨论】:

    • 这是一个非常聪明的解决方案。谢谢!
    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2020-07-12
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多