2

Suppose I want to plot New York or Ohio using R:

library('ggplot2')
library('map')
library('raster')

map <- raster::getData("GADM",country='USA',level=1)
map <- map[map$NAME_1 %in% c('Ohio'),]
map <- map_data(map)

ggplot() + 
  theme_void() +
  geom_polygon(data = map, 
           aes(x=long, y = lat, group = group), 
           fill="grey", alpha=0.3)

Here are the results:

New York Plot

Ohio

How can I not display extra land in the Ohio plot, and only display land for New York?

It looks like it plots the state borders, see google maps for comparison.

0

1 Answer 1

1

Similarly to what you are getting for New York, the extra bit in Ohio represents the state border on Lake Erie and might therefore be a property of the GADM data. This approach uses the data from the maps package and plots the state borders on land:

library('ggplot2')
library('maps')

map <- map_data('state')
ohio <- subset(map, region %in% "ohio")
newyork <- subset(map, region %in% "new york")

ggplot() + 
  theme_void() +
  geom_polygon(data = ohio, 
               aes(x=long, y = lat, group = group), 
               fill="grey", alpha=0.3)
ggplot() + 
  theme_void() +
  geom_polygon(data = newyork, 
               aes(x=long, y = lat, group = group), 
               fill="grey", alpha=0.3)

enter image description here enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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