Home > front end >  GGplot map stretching counties into lakes
GGplot map stretching counties into lakes

Time:09-23

I am trying to make a bivariate US map, but the resulting map seems to stretched counties beyond their borders into lakes, particularly the great lakes region. I've tried both fipio::fips_county() and tigris::counties(year = 2020, class = "sf", resolution = "20m") in order to extract the shapefile/coordinates, both of which output the map like the one displayed. Is there a way to fix this?

Thank you

enter image description here

Example code, not of photo displayed:

library(tidyverse)
library(ggplot2)
library(cowplot)
library(sf)
library(biscale)
library(fipio)

all_counties <- tigris::counties(year = 2020, class = "sf", resolution = "20m")

all_counties <- all_counties %>%
  # mutate(geometry = fips_geometry(GEOID)) %>%
  filter(!grepl("^(02|15)", GEOID))


all_counties <- bi_class(all_counties, x = ALAND, y = AWATER, style = "quantile", dim = 3) 

# create map
map <- ggplot()  
  geom_sf(data = all_counties, mapping = aes(fill = bi_class, geometry=geometry), color = "white", size = 1, show.legend = FALSE)  
  bi_scale_fill(pal = "GrPink", dim = 3)  
  bi_theme()
map

legend <- bi_legend(pal = "GrPink",
                    dim = 3,
                    xlab = "More Land ",
                    ylab = "More Water ",
                    size = 7)
finalPlot <- ggdraw()  
  draw_plot(map, 0, 0, 1, 1)  
  draw_plot(legend, 0.05, .2, 0.2, 0.2)

finalPlot

CodePudding user response:

The area beneath the water is still part of the country, so they are there, rightfully so. There are a couple of ways of solving this. Take a look at the following:

enter image description here

  • Related