## Using {biscale} to plot bivariate raster maps
library(ggplot2)
library(biscale)
library(cowplot)
library(raster)
#> Loading required package: sp
## Load rasterbrick (R logo)
rlogo <- brick(system.file("external/rlogo.grd", package="raster"))
plotRGB(rlogo)
plot(rlogo)
## Convert to data frame
rlogodf <- as.data.frame(rlogo, xy = TRUE)
## Create bivariate classes
rlogodf <- bi_class(rlogodf, x = "red", y = "blue")
## Plot
map <- ggplot(rlogodf) +
geom_raster(aes(x, y, fill = bi_class), show.legend = FALSE) +
bi_scale_fill(pal = "DkViolet") +
bi_theme() +
labs(x = "", y = "")
legend <- bi_legend(pal = "DkViolet",
xlab = "More Red",
ylab = "More Blue",
size = 8)
finalPlot <- ggdraw() +
draw_plot(map, 0, 0, 1, 1) +
draw_plot(legend, 0.1, .75, 0.2, 0.2)
finalPlot
Created on 2021-07-21 by the reprex package (v2.0.0)