[Rd] Choropleths maps of the USA states (PR#9111)

Chris Lawrence lawrencc at debian.org
Tue Aug 1 05:44:17 CEST 2006


On 7/31/06, mlcarvalho at fc.ul.pt <mlcarvalho at fc.ul.pt> wrote:
> I have a problem with the choropleths maps of the USA states=20
>
>  In fact, when I use the following code
>
> #####################################################
>
> palette(gray(seq(0,.9,len=3D10)))
>
>  ordena.estados<-c("ALABAMA","ARIZONA","ARKANSAS","CALIFORNIA","COLORADO",
> "CONNECTICUT","DELAWARE","FLORIDA","GEORGIA","IDAHO","ILLINOIS","INDIANA","=
> IOWA",
> "KANSAS",
> "KENTUCKY","LOUISIANA","MAINE","MARYLAND","MASSACHUSETTS","MICHIGAN","MINNE=
> SOTA","MISSISSIPI",
>  "MISSOURI", "MONTANA","NEBRASKA","NEVADA","NEW HAMPSHIRE","NEW JERSEY",
> "NEW MEXICO","NEW YORK",
> "NORTH CAROLINA","NORTH DAKOTA","OHIO","OKLAHOMA","OREGON","PENNSYLVANIA","=
> RHODE ISLAND",
> "SOUTH CAROLINA",
> "SOUTH DAKOTA","TENNESSEE","TEXAS","UTAH","VERMONT","VIRGINIA","WASHINGTON",
> "WEST VIRGINIA","WISCONSIN","WYOMING")
>
> W<-c(1,10,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1=
> ,1,1,1,1,1,1,1,1,1,1,1,1,1)
>
> mapa.sat<-map('state', region =3D ordena.estados,fill=3DT,col=3DW)=20=20
>
> #####################################################
>
> That should paint all the states with the same colour except   "ARIZONA" , =
>  I get the  "UTAH" state also coloured as "ARIZONA".
>
> The same thing happens with some other states, I get two states coloured in=
> stead of one.
>
> Is there any problem with the way I have made the ranking of states in "ord=
> ena.estados"?

I believe that Michigan and Virginia (at least... there may be others)
have more than one polygon.  So... you end up not having enough colors
in the list and it wraps around.

I once put together a little recipe including a call to grep() that
handled the duplicate polygons.  Try something like:

regions <- map('state', namesonly=T)
W <- rep(1, length(regions))
W[grep('^arizona', regions, ignore.case=T)] <- 10
map('state', fill=T, col=W)

It should also work for the weird states like Michigan and Virginia
(with the appropriate change to the grep call).

Hope this helps...


Chris



More information about the R-devel mailing list