I would like to add some arrows to a categorical raster plot. Using Base R (on a non-ratified raster) as an example:
r <- raster(nrow=10, ncol=10, crs='+proj=utm +zone=1')
r[] = 1
r[51:100] = 3
r[3:6, 1:5] = 5
plot(r)
arrows(100, 50,
0, 50,
length = 0.1,
lwd=2,
col="red"
)
In levelplot you must first ratify your raster and add the appropriate levels:
r <- raster(nrow=10, ncol=10, crs='+proj=utm +zone=1')
r[] = 1
r[51:100] = 3
r[3:6, 1:5] = 5
r <- ratify(r)
rat <- levels(r)[[1]]
rat$landcover <- c('Pine', 'Oak', 'Meadow')
rat$class <- c('A1', 'B2', 'C3')
levels(r) <- rat
levelplot(r)
How can I add the red arrow (as shown in example 1) to the levelplot()
shown in the second block of code?
Thanks.
You can solve it with layer
and panel.arrows
:
levelplot(r) +
layer(panel.arrows(100, 50, 0, 50,
col = 'white'))