Search code examples
rggplot2ggmap

How to fix overlaying polygons in US map?


The below gives overlaying polygons, how to fix it?

library(ggplot2)
ggplot(data = map_data("state")) + geom_polygon(aes(long, lat, group = region), 
  color = "red", fill = "red", alpha = 0.2)

Solution

  • You shoud use group = group as an argument of geom_poly please see as below:

    library(ggplot2)
    ggplot(data = map_data("state")) + 
      geom_polygon(aes(long, lat, group = group), 
                   color = "red", fill = "red", alpha = 0.2)
    

    Output: map