[R] colored maps again
Greg.Snow at imail.org
Thu Feb 19 20:56:20 CET 2009
The problem is that the order and number of polygons in map does not match your data (most likely).
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
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Alina Sheyman
> Sent: Thursday, February 19, 2009 9:46 AM
> To: r-help at r-project.org
> Subject: [R] colored maps again
> I'm trying to create a colored map that would show the number of
> per state.
> My data frame consists of two columns - state and count.
> I'm using the following code
> I'm getting a map, but the values are not being mapped to correct
> What do I need to do to fix that?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help