[R] Color Alaska in USA map

Xin Sun selma at k-state.edu
Fri Nov 19 19:47:50 CET 2010


Hello:

    I have a problem when I tried to color the USA map with different colors. The following is my data (I only used the second column of data):

alaska,	       1, 2
Hawaii,         0, 0
USA,            5, 5

And here is my code:

library("latticeExtra")
library("mapproj")
state<-read.table("C:\\usaclass.txt",sep=",")
state
range<-with(state,range(state[1:3,3]))
range
nbreaks=6
breaks<-do.breaks(range,nbreaks)
StateName<-state[1:3,1]
StateName
mapplot(StateName~state[1:3,3],data=state,breaks=breaks,
map=map("world", c("USA", "Hawaii"), fill=TRUE) ,scales=list(draw=FALSE),
colramp = colorRampPalette(c("white", "black")),xlab=NULL)

After I run this code, the continental USA could be colored, but  alaska is not colored. I have tried to write alaska as "Alaska" and "USA:alaska". However, it does not work. Do you have any suggestion? Thanks!


Sun



More information about the R-help mailing list