Josh Browning
2012-Sep-12 15:38 UTC
[R] Plotting US States: Issue with filled colors cycling
I'm having issues when trying to do a filled State plot using the maps() package. It seems that the color values aren't being plotted correctly, and I'm not sure why... I've started debugging it, but I'm stuck. I've attached the code that I've got so far. The for loop plots states 1:i. What I'm noticing is that the colors are correct until after Michigan gets plotted (i=24). Then, the colors change each time the for loop is executed. I'm guessing it has something to do with Michigan having multiple regions, but I have no idea what to do from here. Help! (and thanks for taking the time to read this/help me out) state = c("Alabama","Alaska","Arizona","Arkansas", "California","Colorado","Connecticut","Delaware", "District Of Columbia","Florida","Georgia", "Hawaii","Idaho","Illinois","Indiana", "Iowa","Kansas","Kentucky","Louisiana", "Maine","Maryland","Massachusetts", "Michigan","Minnesota","Mississippi","Missouri", "Montana","Nebraska","Nevada","New Hampshire", "New Jersey","New Mexico","New York","North Carolina", "North Dakota","Ohio","Oklahoma","Oregon", "Pennsylvania","Rhode Island","South Carolina","South Dakota", "Tennessee","Texas","Utah","Vermont", "Virginia","Washington","West Virginia","Wisconsin","Wyoming") dState = data.frame( col=rbinom(51,size=2,prob=.6)+1, state=state ) for( i in 1:51 ){ dTemp = dState[1:i,] map("state", regions = dTemp$state, # boundary = TRUE, # lty = 1, lwd =1, col= dTemp$col, fill=T) readline( paste( "Current i is", i ) ) } [[alternative HTML version deleted]]
Kevin Wright
2012-Sep-13 02:21 UTC
[R] Plotting US States: Issue with filled colors cycling
Even this one-liner shows Michigan with 2 colors. map("state", col=1:3, fill=TRUE) This link might help: http://tolstoy.newcastle.edu.au/R/devel/06/08/6354.html Kevin On Wed, Sep 12, 2012 at 10:38 AM, Josh Browning <rockclimber112358 at gmail.com> wrote:> I'm having issues when trying to do a filled State plot using the maps() > package. It seems that the color values aren't being plotted correctly, > and I'm not sure why... > > I've started debugging it, but I'm stuck. I've attached the code that I've > got so far. The for loop plots states 1:i. What I'm noticing is that the > colors are correct until after Michigan gets plotted (i=24). Then, the > colors change each time the for loop is executed. I'm guessing it has > something to do with Michigan having multiple regions, but I have no idea > what to do from here. Help! (and thanks for taking the time to read > this/help me out) > > state = c("Alabama","Alaska","Arizona","Arkansas", > "California","Colorado","Connecticut","Delaware", > "District Of Columbia","Florida","Georgia", > "Hawaii","Idaho","Illinois","Indiana", > "Iowa","Kansas","Kentucky","Louisiana", > "Maine","Maryland","Massachusetts", > "Michigan","Minnesota","Mississippi","Missouri", > "Montana","Nebraska","Nevada","New Hampshire", > "New Jersey","New Mexico","New York","North Carolina", > "North Dakota","Ohio","Oklahoma","Oregon", > "Pennsylvania","Rhode Island","South Carolina","South Dakota", > "Tennessee","Texas","Utah","Vermont", > "Virginia","Washington","West Virginia","Wisconsin","Wyoming") > > dState = data.frame( col=rbinom(51,size=2,prob=.6)+1, state=state ) > > for( i in 1:51 ){ > dTemp = dState[1:i,] > map("state", regions = dTemp$state, > # boundary = TRUE, > # lty = 1, lwd =1, > col= dTemp$col, > fill=T) > readline( paste( "Current i is", i ) ) > } > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Kevin Wright