Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding scale labels to levelplot's margins

Tags:

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? enter image description here

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)   
like image 285
Geo-sp Avatar asked Nov 03 '17 16:11

Geo-sp


1 Answers

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)))

Margin labels

like image 199
Christopher Stephan Avatar answered Oct 12 '22 23:10

Christopher Stephan