I'm trying to use ggplot to plot the polygons of a shapefile (this one) in order to visualize some data about the regions contained therein. The code below produces an error:
library(rgdal)
library(tidyverse)
library(maptools)
hsa <- readOGR(dsn = "Data/hsa_bdry", layer = "HSA_Bdry") %>% fortify(region = "HSA93")
ggplot() + geom_polygon(data = hsa, aes(x = long, y = lat, group = group))
Error: TopologyException: Input geom 0 is invalid: Self-intersection at or near point -103.18495682693303 24.986200983871445 at -103.18495682693303 24.986200983871445
How can I keep the data from the shapefile @data slot attached to the fortified data frame without getting plotting errors?
What I've tried so far:
If I remove the region argument from fortify it succeeds in producing a map, but I need the region id so I can merge on the rest of my data (to pass to aes arguments in ggplot).
I tried adding spTransform(CRS("+init=epsg:4269")) to my pipeline before calling fortify (the documentation for the shapefile says it uses North American Datum 1983, which is EPSG 4269) but then I get an error
Error in spTransform(xSP, CRSobj, ...) : No transformation possible from NA reference system



