Locking color key in levelplot in r

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

I am using levelplots to display matrices and the plots are below. Though same col.regions are used for both the plots, the colour key is different. How can we lock (or set) the colour key for both level plots? I want the same colour key (0 to 60) for both plots.

回答1:

Try setting the at and colorkey parameters.

In my example, I use the rasterVis package, which just extends the lattice plotting functions for rasters, but it should not be 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) 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!