[R] Maps package, coloration

From: Michaell Taylor <michaell.taylor_at_boxwoodmeans.com>
Date: Fri 14 Oct 2005 - 08:49:23 EST

I am having some trouble getting the colors correct on county maps using the maps package. I have a data.frame that contains coloration data for every county -- it also contains a variable 'mapm' which fits the 'state,county' format used in the mapping package.

I use this to define colors from a range of 1:100. The problem is that the colors seem good for some states/counties, but random for others. It is almost as if the index has been scrambled, but I find that the ordering is fine in the data.frame.

I am completely confused, any guidance as to what simple thing that I am missing here. Any suggestions greatly appreciated.

data(countyMapEnv)
all.names <- map('county',namesonly=T)
all.names1 <- data.frame(mapm=all.names, col=NA,ordin=1:length (all.names))
# created a dataframe, to be sure of the
# order, I include a variable 'ordin' to index later

# next I merge in the data to use for coloration
# the merge works well, with every element matched
t <- merge(final[,c('PVar','mapm')],all.names1)
# check order once more (redundant perhaps, but I was desperate)
t <- t[order(t$ordin),]

# a little accounting for the colors

t$PVar <- (t$PVar-min(t$PVar,na.rm=T))/(max(t$PVar,na.rm=T)-min(t $PVar,na.rm=T))
t$col <- round((((t$PVar*100)-100)*-1),0)

# t$col is now a collection of integers from 1 to 100

# again, redundancy out of desperation.
matchm <- match.map('county',t$mapm,exact=T,warn=T)

# define colors with the heat.map palette
color <- heat.colors(100)[t$col[matchm]]
# alternative (also not working)

color <- heat.colors(100)[t$col]

# use the colors to fill the map

map('county',fill=T,col=color)

Michaell Taylor

-- 
================
Michaell Taylor, Phd
Principal

Boxwood Means, Inc
Two Stamford Landing
Suite 100
68 Southfield Avenue
Stamford, CT 06902

(T) 203-653-4100

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Oct 14 09:05:51 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:51:45 EST