First off, I am VERY new to spatial analysis and also new to R so please be
gentle!

I am trying to use map2SpatialPolygons in a script to create a kernel
density plot of some data in a subset of US States. I keep getting an error
that "map and IDs differ in length".

I know that this code works (from the help for map2SpatialPolygons):

*nor_coast_poly <- map("world", "norway", fill=TRUE, col="transparent",
plot=FALSE, ylim=c(58,72))
IDs <- sapply(strsplit(nor_coast_poly$names, ":"), function(x) x[1])
nor_coast_poly_sp <- map2SpatialPolygons(nor_coast_poly, IDs=IDs,
proj4string=CRS("+proj=longlat +datum=wgs84"))
*
this code also works:

*usmap <- map('usa', fill=TRUE, col="transparent", resolution=0, plot=FALSE)
uspoly <- map2SpatialPolygons(usmap, IDs=usmap$names,
proj4string=CRS("+proj=longlat +datum=WGS84"))
*
but this code does not:

> states.to.plot=c("illinois", "indiana", "ohio")> dmap<-map("state", regions=states.to.plot, col="transparent", plot=FALSE)> dpoly <- map2SpatialPolygons(dmap, IDs=dmap$names, proj4string=CRS("+proj=longlat +datum=WGS84"))Error in map2SpatialPolygons(dmap, IDs = dmap$names, proj4string = CRS("+proj=longlat +datum=WGS84")) :
  map and IDs differ in length



Can someone tell me how to get the IDs correct?


-- 
Mark Huckabee

	[[alternative HTML version deleted]]

