1

The R package {usmap} provides a convenient way to create maps of the United States using {ggplot2}. You can easily draw borders around state boundary lines or even county boundary lines. For example, here is a basic map of the US generated from this package:

library(usmap)
plot_usmap()

enter image description here

However, what if I instead wanted to draw the boundary lines around groupings of states? So instead of having the boundary line around Texas drawn, the boundary line around Louisiana drawn, and the boundary line around Mississippi drawn, I would want the boundary around the total area of the combination of Texas, Louisiana, and Mississippi. In my specific application, I want to draw boundaries around the federal circuit court jurisdictions, so the result might look something like this, at least with respect to the thicker boundary lines drawn on this picture:

enter image description here

Does anyone know how I can accomplish this, preferably in {ggplot2}? Something I have tried looking into is calculating the alpha shape (using, e.g., the {alphahull} package), but I haven't quite figured out how to make that work for this task.

duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • 2
    Related: https://stackoverflow.com/questions/72708323/how-merge-specific-states-together-by-group-with-one-label-in-ggplot2-in-r – stefan May 16 '23 at 13:34
  • Oh cool, thanks for that very helpful related question @stefan ! I didn't see it in my searching about the issue, I will see if the answers there fully address this, and if so, I will mark my question as a duplicate of that one. – duckmayr May 16 '23 at 13:36

1 Answers1

2

I came up with this solution which is a path to your end goal. You'd have to modify it further. This draws out the map with ggplot and then outlines and labels a defined group of states

pacman::p_load(usmap,BiocManager,sf,devtools,tidyverse)
devtools::install_github("wmurphyrd/fiftystater")
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
library(fiftystater)

sf_fifty <- sf::st_as_sf(fifty_states, coords = c("long", "lat")) %>% 
    group_by(id, piece) %>% 
    summarize(do_union = FALSE) %>%
    st_cast("POLYGON") %>% 
    ungroup()

eight <- sf_fifty %>%
    filter(
        id %in% c(
            "iowa","minnesota","missouri","nebraska","north dakota",
            "south dakota","arkansas"
        )
    ) %>%
    summarise(id = "eight")

ggplot() +
    theme_minimal() +
    geom_sf(data = sf_fifty) +
    geom_sf(data = eight) +
    geom_sf_text(
        data = eight,
        aes(label = "8"),
        size = 3,
        color = "blue",
        nudge_x = -0.1,
        nudge_y = 3.0
    )
stefan_aus_hannover
  • 1,777
  • 12
  • 13