I am trying to create a map with selected states based on highest to lowest mean cost. The following code properly selects the correct states, and the legend is properly color coded with ranges, but the colors per range does not match the state colors. I need help getting the state colors to match the ranges outlined in the legend. I have tried ordering the mean amounts and this correctly creates the vector of colors in the correct order, but when applied to the map the colors don't match. Attached is the R dataset of my data. Please help me tweak the map so the colors are properly assigned.
# Get the entire US map for use later. us.map <- map("state", plot = FALSE, fill = TRUE) # Calculate the range of the map (with extra margins). xl <- extendrange(us.map$range[1:2]) yl <- extendrange(us.map$range[3:4]) library(maps) library(lattice) library(latticeExtra) library(RColorBrewer) # creates nice color schemes library(classInt) plotclr <- brewer.pal(nclr,"PuRd") class <- classIntervals(NatSTSummaryHigh.abi$STMean, nclr, style="fisher" ) colcode <- findColours(class, plotclr) # Plot a multi-panel map of all the states, and colour xyplot(y~x | NatSTSummaryHigh.abi$PrimaryDX, data = state.center,groups=names(attr(colcode, "table")), main="High Cost States by Diagnosis ( > National Avg)", xlim = xl, ylim = yl, scales = list(draw=FALSE), aspect = "iso", xlab = NULL, ylab = NULL, strip = strip.custom(var.name="Diagnosis", sep=": ", strip.names=TRUE, strip.levels=TRUE), auto.key=list(border=TRUE,space="right",text=names(attr(colcode, "table"))), par.settings = simpleTheme(pch=16,col=attr(colcode, "palette"),cex=0.9), subscripts = TRUE, panel = function(..., subscripts) { # Plot the entire US map. panel.polygon(us.map$x,us.map$y) # Select the states to plot. core.states=map("state", regions=NatSTSummaryHigh.abi$JurisdtnStateName[subscripts], plot=FALSE, fill=TRUE) # Plot the states. panel.polygon(core.states$x, core.states$y, col = trellis.par.get("superpose.line")$col) } ) Chris Anderson Data Analyst Medical Affairs wk: 925-677-4870 cell: 707-315-8486 Fax:925-677-4670 </pre><br>This electronic message transmission, including any attachments, contains <br>information which may be confidential, privileged and/or otherwise exempt <br>from disclosure under applicable law. The information is intended to be for the <br>use of the individual(s) or entity named above. If you are not the intended <br>recipient or the employee or agent responsible for delivering the message <br>to the intended recipient, you are hereby notified that any disclosure, copying, <br>distribution or use of the contents of this information is strictly prohibited. If <br>you have received this electronic transmission in error, please notify the sender <br>immediately by telephone (800-676-6777) or by a "reply to sender only" <br>message and destroy all electronic and hard copies of the communication, <br>including attachments. Thank you.<br><br>For more information on Paradigm Management Services, LLC, please visit <br>http://www.paradigmcorp.com <br>
______________________________________________ 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.