I would like to plot a legend with two axes. Specifically, I have combined two spatial objects that have been classified, the first showing intensity of an event and the second showing the probability of the event at that location. I want to create a legend that shows where the pixels of the combined raster fall in each category. The legend I'd like to create would look something like this: Legend with two axes.
The normal legend of the classified data looks like this: Original legend
Here is a reproducible example of the type of data I'm using:
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"))
The easiest way would be to create the plot and add the legend later in a graphics editor.... but I'm sure there must be a way to do this in R itself! I'm currently plotting with the rasterVis package, but if there are answers in ggplot or base R, these are equally welcome.
If it would be more useful to have a reproducible example of the intermediate steps (ie with the intensity/ probability rasters) let me know and I can produce those.
rasterVis
I produced this image. If this is what you are looking for, try the code available here (section "Bivariate legend). – NitroparaffinReduce
and+.trellis
. – Nitroparaffin