I am new to R and was following the following tutorial on the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the bas
Include three of those files (extensions: dbf, shp, shx) in the same folder.
In case this helps anyone:
I had the same problem but none of the solutions worked. Worst, I the same was going on with an script that I'm 100% sure was working previously.
Turns out that it could also be that the shapefile gets damaged. Apparently this can happen while the file is being manipulated (or so that say my geographer friends), so next time you try to open it won't work for no apparent reason. Downloading it again worked fine, but makes me think to have a copy of the more precious ones just in case.
There is one more, but not much automatic solution which helped me:
file<- readShapePoly(file.choose())
Then just find your *.shp file and run it.
I had a similar issue, and it was because there were several other files along with the '*.shp' shape file in the zip package that I downloaded. Then I only moved the shape file to another folder and it didn't work. When including all files together, it was fine and I could readShapeSpatial()
function okay.
I had the same problem. I found out that basically you need three of those files: .shp, .shx and .dbf
Forget ggplot
and gpcclib
. Stick to maptools
and rgdal
that actually provide tools for reading a shapefile.
Don't just say you've tried "this and that", outline the details. For example, does `file.exists("london_sport.shp") return TRUE?
Also, what makes you think readShapePoly()
is the right function? It only knows how to read polygon shapefiles, try readShapePoints()
and readShapeLines()
as well.
If you can, try readOGR
which can read a shapefile despite many caveats (including the geometry type).
library(rgdal)
readOGR("~/Documents/R Projects/Intro to ggplot2", "london_sport")
If you can report on all of those things it's likely someone could help.