Match color with numbers Raster Map R -


i match color raster class. assume have following colors , these rasters:

library(rastervis) mycolors=c("darkred","red3", "orange", "yellow", "lightskyblue",            "royalblue3","darkblue") s <- stack(replicate(6, raster(matrix(runif(100), 10)))) levelplot(s, layout=c(3, 2), col.regions=mycolors, index.cond=list(c(1, 3, 5, 2, 4, 6))) 

i classify rasters in "s" such values 0 0.1 colored in "darkred" , values 0.9 1 colored in "darkblue". basically, classify data "n" classes , assign each class color of choice.

finally,the colorkey should have labels various raster classes. insights found here 1 , 2

you have convert each layer factor ratify using cut function define breaks.

library(rastervis)  s <- stack(replicate(6,                      raster(matrix(runif(100), 10))))  brks <- seq(0, 1, .1) ## these labels included levels in rat labs <- levels(cut(s[], brks))  ## auxiliary function convert each layer factor. makefactor <- function(r){     r <- ratify(cut(r, brks))     rat <- levels(r)[[1]]     rat$int <- labs     levels(r)[[1]] <- rat     r }  lfactor <- lapply(seq_len(nlayers(s)),                   fun = function(i) makefactor(s[[i]])) sfactor <- stack(lfactor) 

now choose favorite colors , done.

levelplot(sfactor, col.regions = mycolors) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -