The problem is that the order and number of polygons in map does not match your data (most likely).
Try: library(maps) library(plotrix) state.col<-color.scale(state.x77[,'HS Grad'],0,0,c(0,1)) map("state",fill=TRUE,col=state.col) nms <- map('state', plot=FALSE)$names nms <- sub(':.*$','',nms) ind <- match(nms, tolower(state.name)) map('state', fill=TRUE, col=state.col[ind]) Now try it with your data, just replace state.name with the names of the states in the order of your data if it is different (possibly the rownames). You may also want to look at state.vbm in the TeachingDemos package (works with maptools rather than maps) as another way to plot colored maps of the USA that is less affected by geographical area. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Alina Sheyman > Sent: Thursday, February 19, 2009 9:46 AM > To: r-help@r-project.org > Subject: [R] colored maps again > > I'm trying to create a colored map that would show the number of > students > per state. > My data frame consists of two columns - state and count. > I'm using the following code > > library(maps) > map("usa") > library(plotrix) > state.col<-color.scale(gre$count,0,0,c(0,1)) > map("state",fill=TRUE,col=state.col) > > I'm getting a map, but the values are not being mapped to correct > states. > What do I need to do to fix that? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.