2

I want to make a map of the Eastern U.S., however only within the longitude range of -95 degrees to -66.5 degrees I've started using ggplot2.

library(ggplot2)
us_map <- map_data('usa')
map <- ggplot(data=us_map, aes(x=long, y=lat, group=group)) + geom_polygon(fill = 'black')
map

which generates this map: enter image description here

I would like to clip the map to only -95 degrees to -66.5 degrees. I used to do this with the coord_proj function within ggalt package like this:

map <- map + coord_proj("+proj=cea +lat_ts=37.5",ylim = c(25,50), xlim = c(-95,-66.5)) #crib map to eastern US.

However this now throws the error, Error: Not implemented.

Suggestions?

zx8754
  • 52,746
  • 12
  • 114
  • 209
colin
  • 2,606
  • 4
  • 27
  • 57
  • Maybe using sf: https://gis.stackexchange.com/q/371960/61922 – zx8754 Aug 05 '21 at 12:49
  • 1
    Try using `+ coord_fixed(xlim=c(-95, -66.5))`. For me, this worked. – Zoe Aug 05 '21 at 12:51
  • @Zoe this works, but for some reason also adds a bunch of white space once I make a multi-panel figure with `ggarrange()`. – colin Aug 05 '21 at 12:57
  • 1
    I think you might be able to handle this by giving a diferent ratio? Like `coord_fixed(1.5, xlim=c(-95, -66.5))`. The deafult is 1. (I plotted two maps next to each other and for me, it looks okay? Maybe you also have to adjust the `ggarrange()` arguments `width` and `height`?) – Zoe Aug 05 '21 at 13:00
  • 1
    @Zoe that was the answer! Thank you! – colin Aug 05 '21 at 13:20

0 Answers0