[R-sig-Geo] counties plot in R

Roger Bivand Roger.Bivand at nhh.no
Tue Feb 19 08:12:49 CET 2013


On Mon, 18 Feb 2013, Milan Sharma wrote:

> Hi list/ Roger,
> I tried just 3 states as you said, I merged state and county names to make sure the county names are different.
> Here is the error message.
>
> library(maptools)
> library(maps)
> library(spdep)
> library(rgdal)
> library(alr3)
>  data<-read.csv("try3.csv",header=TRUE)
>> attach(data)
>> names(data)
> [1] "State"     "NAME"      "county"    "Longitude" "Latitude"  "yield"   
> [7] "temp"      "precpt"  
>> sd<-map("county", c("Illinois","Indiana","Iowa"), fill=F, plot=F)
>> county.names<-as.character(sd$names)
>> sd.sp<-map2SpatialPolygons(sd, IDs=county.names, proj4string=CRS("+proj=longlat"))
> Error in map2SpatialPolygons(sd, IDs = county.names, proj4string = CRS("+proj=longlat")) :
>   map and IDs differ in length
>>
> How do I solve the problem of matching?

By checking and paying attention. You have fill=FALSE (never ever use F 
for FALSE or T for TRUE, try T <- FALSE to see why this is bad), but in an 
earlier reply, I said fill=TRUE (to return polygons, not line segments). 
You could find this out by reading ?map.

I do not have time for trivial questions to which I have already replied, 
hand-holding decreases learning, this terminates my input to your project.

Roger

> Milan
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list