- 
                Notifications
    You must be signed in to change notification settings 
- Fork 245
Open
Description
The image and code examples of the hexbin map are distorted because they are using an incorrect CRS. This can be set with the st_transform() function. The basemap that you direct the user to download appears to use the Google Maps Mercator (https://epsg.io/900913).
The introductory code block could be changed to include this correction:
# library
library(tidyverse)
library(sf)
library(RColorBrewer)
# Download the Hexagon boundaries at geojson format here: https://team.carto.com/u/andrew/tables/andrew.us_states_hexgrid/public/map.
# Load this file. (Note: I stored in a folder called DATA)
my_sf <- read_sf("DATA/us_states_hexgrid.geojson.json")
# Bit of reformatting
my_sf <- my_sf %>%
  mutate(google_name = gsub(" \\(United States\\)", "", google_name))
# Set CRS
my_sf <- st_transform(my_sf , crs = 900913)
# Show it
plot(st_geometry(my_sf))
This appears on https://r-graph-gallery.com/328-hexbin-map-of-the-usa.html
Metadata
Metadata
Assignees
Labels
No labels