Color key lock in levelplot in r

I use levelplots to display matrices, and the graphs below. Although the same col.regions are used for both charts, the color key is different. How can we lock (or set) a color key for both levels? I want the same color key (from 0 to 60) for both charts.

enter image description here

enter image description here

+4
source share
1 answer

Try setting the at and colorkey parameters.

In my example, I use the rasterVis package, which simply extends the lattice build functions for rasters, but this is not necessary. I just wanted to use the BuRdTheme() function to set my own theme.

Example:

 require(rasterVis) # My matrix my.mat1 <- matrix(rnorm(5*5),5,5) my.mat2 <- matrix(rnorm(5*5,2,2),5,5) # Custom theme (from rasterVis package) my.theme <- BuRdTheme() # Find the min and max values my.min <- min(my.mat1, my.mat2) my.max <- max(my.mat1, my.mat2) # Customize the colorkey my.at <- seq(my.min, my.max, length.out=length(my.theme$regions$col)-1) my.ckey <- list(at=my.at, col=my.theme$regions$col) # Level plot levelplot(my.mat1, par.settings=my.theme, at=my.at, colorkey=my.ckey) levelplot(my.mat2, par.settings=my.theme, at=my.at, colorkey=my.ckey) 

my.mat1my.mat2

+8
source

Source: https://habr.com/ru/post/1498480/


All Articles