Error when using fortify -- IllegalArgumentException

152 views
Skip to first unread message

Max Livingston

unread,
Aug 30, 2013, 11:31:14 PM8/30/13
to ggp...@googlegroups.com
Hi everyone,

I'm pretty new to R and ggplot2, but I've successfully plotted shapefiles before using the tutorial here (https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles). However, I ran into an error recently that I couldn't find any info about from Googling around. I'm using shapefile data on police precincts in NYC (available here). The code I'm running is:

precinctmap <- readOGR("data/nyc_precinctmap","nypp")
precinctmap@data$id <- rownames(precinctmap@data)
precinctmap.points = fortify(precinctmap, region="id")

When I run that 3rd line, I get the following error: "Error: IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4"

Now, it seems like this may be an issue with the shapefile, perhaps? But when I just do plot(precinctmap) it looks totally fine. Does anyone have any ideas?

Thanks!
Max

Madalyn Blondes

unread,
Dec 17, 2014, 6:19:07 PM12/17/14
to ggp...@googlegroups.com
Hi Max,

I see this is an old post, but I'm wondering if you ever managed to solve this problem.  I was plotting shape files fine last week using the same link you provide, and now suddenly I'm getting the exact same error when I use the fortify function. Hopefully you figured out the issue a while back and can share it - I've been searching for days and haven't yet found a solution.

thank you,
Madalyn

Chaz Thomas

unread,
Sep 22, 2016, 4:18:20 PM9/22/16
to ggplot2
Following up on Madeline and Max - I too am wondering if anyone has been able to solve this issue with this particular NYC precinct shapefile?? 2 years later and still receiving the same "Error: IllegalArgumentException: Invalid number of points" error that was observed before.

Thanks!
-Chaz
Reply all
Reply to author
Forward
0 new messages