tidyVA includes simple features tibbles of VHA geographies.
For this example we’ll use the submarket dataset. This is a tidy
dataframe that includes simple features geometry for VHA submarket regions. Although accurate, this output is not very easy to work with.
Since this is now in tidy format, we can easily filter and manipulate the data. The function shift_geo()
in tidyVA will project and repositon Alaska and Hawaii. Additionally, an sf object can be mapped multiple times as individual layers representing different attributes:
submarket <- shift_geo(submarket)
ggplot() +
geom_sf(data = submarket,
aes(fill = VISN), color = NA) +
geom_sf(data = submarket, fill = NA,
color = "#ffffff", size = .5) +
theme_minimal() +
theme(legend.position = "bottom") +
guides(fill = guide_legend(nrow = 2)) +
scale_fill_viridis_d()
Alternatively, you can aggregate this dataset to the VISN level, and use as needed. Keep in mind that VHA submarkets in the Caribbean and the Pacific Ocean, are not included - thus, VISNs 21 and 8 are not fully represented.
visn <- submarket %>%
group_by(VISN) %>%
summarise()
ggplot() +
geom_sf(data = visn, aes(fill = VISN),
show.legend = FALSE) +
theme_minimal() +
scale_fill_viridis_d()
A major limitation of the original data is that attributes are present based on a geography’s hierachy. The county
dataset has VHA attributes in addition to State and County attributes. The visn
dataset only has a VISN attribute:
data("states")
data("visn")
glimpse(visn)
#> Observations: 18
#> Variables: 4
#> $ VISN <chr> "01", "02", "04", "05", "06", "07", "08", "09", "10", "1...
#> $ Shape_Leng <dbl> 133.20427, 80.95749, 48.00316, 97.94793, 166.43208, 60.9...
#> $ Shape_Area <dbl> 19.12818, 15.28981, 14.14237, 12.04503, 21.12288, 31.413...
#> $ geometry <MULTIPOLYGON [°]> MULTIPOLYGON (((-73.62286 4..., MULTIPOLYGO...
With simple features we can easily perform geometric operations and gather attributes based on a spatial relationship:
visn_st <- sf::st_intersection(states, visn)
glimpse(visn_st)
#> Observations: 151
#> Variables: 13
#> $ STATEFP <chr> "09", "50", "23", "25", "33", "36", "44", "09", "34", "4...
#> $ STATENS <chr> "01779780", "01779802", "01779787", "00606926", "0177979...
#> $ AFFGEOID <chr> "0400000US09", "0400000US50", "0400000US23", "0400000US2...
#> $ GEOID <chr> "09", "50", "23", "25", "33", "36", "44", "09", "34", "4...
#> $ STUSPS <chr> "CT", "VT", "ME", "MA", "NH", "NY", "RI", "CT", "NJ", "P...
#> $ NAME <chr> "Connecticut", "Vermont", "Maine", "Massachusetts", "New...
#> $ LSAD <chr> "00", "00", "00", "00", "00", "00", "00", "00", "00", "0...
#> $ ALAND <dbl> 12542638347, 23873467535, 79885221885, 20204442852, 2318...
#> $ AWATER <dbl> 1815476291, 1031124865, 11748755195, 7130620748, 1028678...
#> $ VISN <chr> "01", "01", "01", "01", "01", "01", "01", "02", "02", "0...
#> $ Shape_Leng <dbl> 133.20427, 133.20427, 133.20427, 133.20427, 133.20427, 1...
#> $ Shape_Area <dbl> 19.12818, 19.12818, 19.12818, 19.12818, 19.12818, 19.128...
#> $ geometry <GEOMETRY [°]> MULTIPOLYGON (((-72.75991 4..., POLYGON ((-73.4...
We can now filter this dataframe by VISN and keep State attributes
visn_st %>%
filter(VISN %in% c("01","02")) %>%
ggplot() +
geom_sf(aes(fill = VISN), color = "#ffffff") +
scale_fill_viridis_d(option = "cividis") +
theme_va()
Or by State, and keeping VISN attributes. New York for example is mostly within VISN 2, but, there are small catchments areas in the Western and Southern parts of the state that are outside VISN 2.
tidyVA also includes a ggplot theme: theme_va()
.
This theme has several possible parameters. The core of this function is theme_ipsum
from hrbrthemes, but with some changes to the defaults.
data("visn")
visn %>%
ggplot(aes(reorder(VISN,Shape_Area), Shape_Area)) +
geom_col() +
labs(x = "VISN", y = "Shape Area",
caption = "CRS - EPSG:4326") +
ggtitle("Shape Area of VA Service Networks",
subtitle = "This is an example plot") +
theme_va(grid = "Y")
When plotting maps, you may want to remove the axis text from geom_sf(). For this, the map
argument of theme_va()
can be set to TRUE.
Additionally, setting the grid_col
argument to “transparent” will remove panel grid lines from the plot.
visn_st %>%
filter(STUSPS %in% c("NY","CT","VT","ME", "MA","NH")) %>%
ggplot() +
geom_sf(aes(fill = NAME), color = "#ffffff") +
scale_fill_viridis_d(option = "cividis") +
labs(caption = "Caption wil go here", fill = "") +
ggtitle("Example Plot for Maps",
subtitle = "Cividis Palette goes well with VA theme") +
theme_va(map = TRUE, grid_col = "transparent")