I'd like to add label showing the values of latitudinal zonal averages to levelplot's gray margin. In the following example, the min and max values for latitudinal means are 286 and 751 respectively. Any suggestion on adding an axis with this information to the margin?
library(raster)
library(rasterVis)
r <- raster(system.file("external/test.grd", package="raster"))
levelplot(r, at=seq(100, 1850, by = 250))
# calculating the latitudinal means
rows <- init(r, v='y')
yAve <- zonal(r, rows, fun='mean',na.rm=TRUE)
summary(yAve)
Use margin=list(axis=TRUE) to add the min and max values to the margin.
library(raster)
library(rasterVis)
r <- raster(system.file("external/test.grd", package="raster"))
levelplot(r, at=seq(100, 1850, by = 250), margin=list(axis=TRUE))
You can change the color and fontsize of the margin labels using gpar.
library(grid)
levelplot(r, at=seq(100, 1850, by = 250), margin=list(axis=gpar(col = 'black', fontsize = 9)))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With