Sunday, April 14, 2013

RG#60: Plot world map and fill colors (heatmap)

 require(maps)

# just random colors
worldmap <- map('world', fill = TRUE, col = rainbow (7))
 
# generating random variable to fill colors
set.seed(123)
filld <- data.frame (country.reg = worldmap$names, yvar = rnorm (length(worldmap$names), 50, 30))

# now device colors from yvar data category
 # brewing color for continious color filling
library(RColorBrewer)
plotclr <- brewer.pal(6,"YlOrRd")#

# categorize in different class for yvar
 filld$colorBuckets <- as.numeric(cut(filld$yvar, c(0, 30, 50, 70, 90, 130)))

# corresponding legend text
legdtxt <- c("<0%", "0-30%", "30-50%", "50-70%", "70-90%", ">90%")


map('world', fill = TRUE, col = plotclr )
legend("bottomleft", legdtxt, horiz = FALSE, fill = plotclr)




 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.