我想用两个轴绘制一个图例。具体来说,我组合了两个已分类的空间对象,第一个显示事件的强度,第二个显示该位置事件的概率。我想创建一个图例,显示组合栅格的像素在每个类别中的位置。我想创建的图例看起来像这样: Legend with two axes。
分类数据的正常图例如下所示:原始图例
这是我正在使用的数据类型的可重现示例:
library(raster)
library(rasterVis)
# setseed
set.seed(999)
# create raster (example of what would be the outcome of combining intensity and probability rasters)
plot.me<- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, ncols=40, nrows=40)
val <- c(100:104, 200:204, 300:304, 400:404)
plot.me<- setValues(plot.me, sample(val,ncell(plot.me),replace=T))
###### Plotting
plot.me <- ratify(plot.me)
levelplot(plot.me,att="ID" ,
col.regions=c("#beffff","#73dfff","#d0ff73","#55ff00",
"#73b2ff","#0070ff","#70a800","#267300",
"#f5f57a","#ffff00","#e8beff","#df73ff",
"#f5ca7a","#ffaa00","#e600a9","#a80084"))
Run Code Online (Sandbox Code Playgroud)
最简单的方法是创建绘图并稍后在图形编辑器中添加图例......但我确信必须有一种方法可以在 R 本身中做到这一点!我目前正在使用 rasterVis 包进行绘图,但是如果 ggplot 或 base R 中有答案,那么这些也同样受欢迎。
如果有一个可重复的中间步骤示例(即使用强度/概率栅格)会更有用,请告诉我,我可以生成这些示例。