# with a SpatRaster
r <- rast(ncols=40, nrows=40, xmin=0, xmax=1, ymin=0, ymax=1, vals=runif(1600))
plot(r, legend=FALSE, mar=c(3.1, 3.1, 2.1, 7.1))
legend_cont("right", legend=r)
# horizontal
plot(r, legend=FALSE, mar=c(6.1, 3.1, 2.1, 2.1))
legend_cont("bottom", legend=r, horiz=TRUE, title="values")
# on the map
plot(r, legend=FALSE, alpha=0.1)
legend_cont(0.1, legend=r)
legend_cont(0.3, c(0.5, 0.9), legend=r, bg="white")
legend_cont(c(0.4, 0.8), 0.2, horiz=TRUE, legend=r, bg="white")
# with a numeric range and custom colors
cols <- heat.colors(100)
vals <- seq(5,95,10)
par(mar=c(3.1, 3.1, 2.1, 7.1))
plot(1:10, col=cols[vals], cex=2, pch=20)
legend_cont("right", legend=c(1, 100), col=cols)
Run the code above in your browser using DataLab