【问题标题】:plot road network of two cities over each other (in the same scale) to compare the sprawl of cities绘制两个城市的道路网络(以相同的比例)以比较城市的蔓延
【发布时间】:2021-10-08 02:35:57
【问题描述】:

受此网站启发 (https://thetruesize.com) 比较国家/地区

如何将road_orlandoroads_miami 相互绘制(相同比例)以直观地比较道路网络的蔓延。

编辑 - 我之前曾要求以小比例并排绘制。

library(tigris)

roads_orlando <- roads(state = "FL",
               county = c("Orlando"))

roads_miami <- roads(state = "FL",
               county = c("Miami-Dade"))

class(roads_orlando)
plot(roads_orlando$geometry)

class(roads_miami)
plot(roads_miami$geometry)

【问题讨论】:

    标签: r sf tmap tigris


    【解决方案1】:

    可以考虑{cowplot};它最适合 ggplots。

    例如,考虑以下代码:

    library(tigris)
    
    roads_orlando <- roads(state = "FL",
                           county = c("Orange")) # Orlando does not seem to be a legit county name :(
    
    roads_miami <- roads(state = "FL",
                         county = c("Miami-Dade"))
    
    # Miami is bigger of the two; we need to enlarge Orlando a bit
    
    bbox_miami <- st_bbox(roads_miami) # bouding box of Miami
    
    width_miami <- bbox_miami[3] - bbox_miami[1]
    height_miami <- bbox_miami[4] - bbox_miami[2]
    
    # centroid of Orlando; to this we will add the extent of Miami
    orlando_centroid <- st_centroid(st_bbox(roads_orlando) %>%
                                      st_as_sfc())
    
    library(ggplot2)
    
    gg_or <- ggplot(data = roads_orlando) +
      geom_sf() +
      coord_sf(xlim = c(st_coordinates(orlando_centroid)[1] - width_miami / 2,
                        st_coordinates(orlando_centroid)[1] + width_miami / 2), 
               ylim = c(st_coordinates(orlando_centroid)[2] - height_miami / 2,
                        st_coordinates(orlando_centroid)[2] + height_miami / 2))
    
    gg_md <- ggplot(data = roads_miami) +
      geom_sf() 
    
    cowplot::plot_grid(gg_or, gg_md)
    

    【讨论】:

    • 感谢@Jindra Lacko,但我想以相同的比例绘制它们以比较网络的蔓延。
    • Oki,我明白了。考虑更新的情节(和代码) - 它迫使奥兰多道路网络(或者更确切地说是橙色 cnty)的情节与迈阿密戴德的范围相同。然后将绘图并排绘制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    相关资源
    最近更新 更多