I'm trying to draw some maps with sf and ggplot2, and I'm having some odd behaviour. I was running the map before using the EPSG projection number 3310, and that worked fine:
world <- st_read("world_map_path.shp")
syear <- st_read("data_path.shp")
proj <- 3310
ggplot(data = world) +
geom_sf() +
geom_sf(data=syear, aes(fill=owner), size=0.2) +
coord_sf(crs=proj)
The above code returns no error, and renders a map perfectly well. However, running almost exactly the same code with a manually input orthographic projection results in an invalid geometry error. Code:
world <- st_read("world_map_path.shp")
syear <- st_read("data_path.shp")
proj <- "+proj=ortho +lon_0=35 +lat_0=90"
ggplot(data = world) +
geom_sf() +
geom_sf(data=syear, aes(fill=owner), size=0.2) +
coord_sf(crs=proj)
Error:
Error in CPL_geos_is_empty(st_geometry(x)) :
Evaluation error: IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 4.
Calls: <Anonymous> ... st_as_grob.sfc_MULTIPOLYGON -> st_is_empty -> CPL_geos_is_empty
Execution halted
What am I doing wrong here? Is there an error in my code, or in my input data? What might said error be?