[R] counties in different colours using map()

Tord Snäll Tord.Snall at nvb.slu.se
Wed Dec 27 12:12:04 CET 2006


Hi,
I would like to plot a map of US counties using different colors. map() 
seems to be the function to use, e.g.
library(maps); map('usa'); map('county', 'colorado', add=T,fill = T, 
col=c(1:5))
plots Colorado counties using colours 1 to 5.

However, I want each color to represent a certain value - a value to be 
picked from a data frame.
This code should show a correspoding map at the level of states:
state.names <- system('tr "[A-Z]" "[a-z]"', state.name)
map.states <- unix('sed "s/:.*//"', map(names=T,plot=F))
state.to.map <- match(map.states, state.names)
color<- votes.repub[state.to.map, votes.year = 1900] / 100
map('state', fill=T, col=color); map('state', add=T)
It is copied from page 6 in
Richard A. Becker, and Allan R. Wilks, "Maps in S", AT&T Bell 
Laboratories Statistics Research Report [93.2], 1993.
http://public.research.att.com/areas/stat/doc/93.2.ps

I also wonder whether the county names are available in the database 
used by map(), and, if yes, how to extract or utilize them.

Thanks!

Tord

-- 

Tord Snäll
Department of Conservation Biology
Swedish University of Agricultural Sciences (SLU)
P.O. 7002, SE-750 07 Uppsala, Sweden
Office/Mobile/Fax
+46-18-672612/+46-730-891356/+46-18-673537
E-mail: tord.snall at nvb.slu.se
www.nvb.slu.se/staff_tordsnall



More information about the R-help mailing list