1

I'm relatively new to using Shapefiles in R. I want to create visualizations of country and district level data for India for which I'm using maptools in R. For the shapefiles, I got the data from gadm.org which includes state/district/subdistrict level data for India.

However, I'm trying to load the file in R and it's just not happening.This is my code :

library(maptools)

dist <- readShapePoly("IND_adm2.shp")

Here IND_adm2.shp is the district level shape file for India.

R is unable to read the file, giving me this error:

"Error in getinfo.shape(filen) : Error opening SHP file"

I'm not really sure what the problem is.I have R 3.0.1, have the files in the appropriate directory but something's just not right. I'm also new to making maps in R so it's been a bit annoying. Any ideas on how to fix this?

horseoftheyear
  • 917
  • 11
  • 23
  • Is that the entire error message? – IRTFM Aug 01 '13 at 06:12
  • Yes that's all I get. – Numbercrunch Aug 01 '13 at 06:35
  • Just tried that, getting the same error with that too – Numbercrunch Aug 01 '13 at 06:45
  • 1
    Try using file.choose() (on Windows, you didn't say your OS) to make sure you really are going to the right file. Then make sure you have the .shp, .shx, and .dbf files in that folder. You need all them – Spacedman Aug 01 '13 at 06:53
  • Ok, just solved the issue. I was just extracting the .shp files as opposed to all three(.shp, .shx and .dbf) previously which was causing the issue. Thanks Spacedman for the help! I'm just getting started with mapping in R as I said so learning along the way. New to this community as well. Thanks to all for the help. Hope to put forth more sensible questions in the future! – Numbercrunch Aug 01 '13 at 06:58
  • I vote to close, this is nothing to do with R and all to do with shapefiles and archives. – mdsumner Aug 01 '13 at 07:09

1 Answers1

3

You could use the package rgdal

library(rgdal)
library(sp)
shp <- readOGR("path/to/shpfiles", "IND_adm2")
plot(shp)
Karsten W.
  • 17,826
  • 11
  • 69
  • 103