2

Edit: I made an embarrassing rookie mistake late at night (excuses, excuses) and flipped my lats and longs. As a result, people searching for an answer to my original question will not be helped by this. To resolve this, I've changed the title to this post to reflect the mistake caught in the accepted answer.

I'm attempting to project some data to a planar coordinate system and the results look very wrong. Here's a reproducible example with a map of New England:

library(rnaturalearth)
library(sf)
library(dplyr)
library(ggplot2)

states_sf <- ne_states(country = "united states of america", returnclass = "sf")
states_names <- c("Maine", "New Hampshire", "Vermont", "Connecticut", 
                  "Rhode Island", "Massachusetts")
states_sf <- filter(states_sf, name %in% states_names)

ggplot(states_sf) + 
  geom_sf() +
  theme_bw()

enter image description here

But when I project and replot the data, it doesn't look as expected.

# Lambert equal-area projection
laea_centered <- "+proj=laea +lat_0=-70.30744 +lon_0=43.15268"
coord_shift <- "+x_0=12019341.4 +y_0=1730136"
proj_ref <- " +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
laea_proj4 <- paste(laea_centered, coord_shift, proj_ref, sep = " ")

states_projected_sf <- st_transform(states_sf, crs = laea_proj4)

ggplot(states_projected_sf) +
  geom_sf() +
  coord_sf(datum = st_crs(states_projected_sf)) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

enter image description here

Just for grins and to further illustrate how absurdly I've managed to mangle this, here's the projected map with geographic coordinates and graticule.

ggplot(states_projected_sf) +
  geom_sf() +
  coord_sf() +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

enter image description here

Can someone explain where I went wrong and how to do this better?

2

Lambert equal-area projection

laea_centered <- "+proj=laea +lat_0=-70.30744 +lon_0=43.15268"

call me crazy, but don't you have the lat and long switched around?

  • Well, that was embarrassing. – Gregory Oct 10 '19 at 12:10
  • Actually, no need to be embarrassed. In my experience this is one of the most common errors people make, guilty as charged. This is a good lesson for everyone to keep in their projection toolbox...the other thing I check often is the coords, especially when using State Plane -- if my projection is not where it should be, sometimes the coords give me clues as to what happened... – jack c Oct 10 '19 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.