[R-sig-Geo] need to create US map with colors by state

Henk Sierdsema Henk.Sierdsema at sovon.nl
Thu Nov 5 20:38:10 CET 2009


Hi Mark,
 
The 'ASDAR'-book (Bivand et al, Applied Spatial Data Analysis with R http://www.asdar-book.org/) contains a lot of examples of desease mapping and modelling. From the website you can also download example data sets and scripts.
 
Here is an (extended) example from page 91 onwards from disease mapping in Scotland.getwd()

library(maptools)
library(rgdal)
library(RColorBrewer)
scot_dat <- read.table("scotland.dat", skip = 1) 
                                ## from http://www.sph.emory.edu/~lwaller/book/ch2/scotland.dat <http://www.sph.emory.edu/~lwaller/book/ch2/scotland.dat> 
names(scot_dat) <- c("District", "Observed", "Expected","PcAFF", "Latitude", "Longitude")
scot_dat$District
scot_LL <- readOGR(".", "scot")  # from http://www.sph.emory.edu/~lwaller/book/ch9/scot.shp <http://www.sph.emory.edu/~lwaller/book/ch9/scot.shp>  ,
                                 # http://www.sph.emory.edu/~lwaller/book/ch9/scot.shx <http://www.sph.emory.edu/~lwaller/book/ch9/scot.shx>   and
                                 # http://www.sph.emory.edu/~lwaller/book/ch9/scot.dbf <http://www.sph.emory.edu/~lwaller/book/ch9/scot.dbf> 
                                 
scot_dat1 <- scot_dat[match(scot_LL$ID, scot_dat$District), ]
row.names(scot_dat1) <- sapply(slot(scot_LL, "polygons"),function(x) slot(x, "ID"))
scot_LLa <- spCbind(scot_LL, scot_dat1)
all.equal(scot_LLa$ID, scot_LLa$District)
str(scot_LLa at data <mailto:scot_LLa at data> )
rw.colors <- colorRampPalette(c("white","red"))
spplot(scot_LLa, "Observed", col.regions=rw.colors(100000), main='number of cases of Scottish Lip cancer' )

 
The most important line here is 'scot_LLa <- spCbind(scot_LL, scot_dat1)' where you can combine your spatial polygones (like a shape imported with 'readShapePoly() or readOGR() ) with a dataframe containing information on the deseases.  

Success,
 
Henk
 
 
 
 
 

________________________________

Van: r-sig-geo-bounces at stat.math.ethz.ch namens Mark Kimpel
Verzonden: do 5-11-2009 18:14
Aan: r-sig-geo at stat.math.ethz.ch
Onderwerp: [R-sig-Geo] need to create US map with colors by state



I need to do something quite simple, but a search of the "CRAN Task View:
Analysis of Spatial Data" has not revealed to me the best way to do this.
What I would like to do is plot a map of the U.S. with each state's color
corresponding to heatmap colors of a population statistic. For example, dark
red could be a state with the highest number of H1N1 cases, pink with an
intermediate number, and white with no cases. An ability to overlay the
center of the state with the actual statistic would be nice but not
necessary.

Is there a straightforward method to accomplish this? A vignette perhaps?

Thanks,

Mark

Mark W. Kimpel MD  ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN  46074

(317) 490-5129 Work, & Mobile & VoiceMail
(317) 399-1219 Skype No Voicemail please

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list