[R-sig-Geo] fixed colors in maps

Katona Lajos katona at statisztikus.hu
Sat Dec 27 22:13:21 CET 2008


Hi,

I have a proble, can you help me? :-)
I'd like to make lots of maps with spplot with fixed colors and color range. There is in the data the "colors" field or variable which can have fixed value: 1, 2, 3, 4, 5, 6, 7, 8, 9. But in an actual date I have not all value in regions for example only 1, 2, 3. When I see the map I have 3 colors but the fist is 1 (white) the second is 5 (medium) and the third is 9 (dark red) from brewer.pal(9, "Reds"). It is not good for me. I'd like to have other 3 colors. When my "colors" variable is 1 the colors code is 1, when 2 then color code is 2, when 3 then color code is 3 from brewer.pal(9, "Reds"). And the legend near the map is always 9 colors.
It is very imoprtant for me becouse I'd like to make an swf file from 365 jpg image.

data_regions$date_num=as.numeric(data_regions$DATE)
max_date=max(data_regions$date_num)
date_lst=seq(1,max_date)
for(i in date_lst){
   actual_data=subset(data_regions, data_regions$date_num==i)
   actual_date=actual_data[1,]$DATE
   file_name=paste("map_",actual_date,".jpg")
   mapname_colors.sp <- SpatialPolygonsDataFrame(mapname.sp, actual_data[,c(2,8)])
jpeg(filename=file_name, width=1024, height=768, units="px",
 pointsize=12, quality=300, bg="white", res=NA, restoreConsole=TRUE)
spplot(mapname_colors.sp, "colors", col.regions=brewer.pal(9, "Reds"), 
 main="Epidemic, etc.", sub=paste("Timestamp:", actual_date))
dev.off()
}

Thank you!




More information about the R-sig-Geo mailing list