Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

levelplot: how to add space between colorkey and x-axis label

I am trying to use levelplot to plot a simple Digital Elevation Model (DEM).

Here is my code:

r1 = raster("ned10dem.tif")
e = extent(460000,480000,4555000,4567500)
rr1 = crop(r1,e)
p = levelplot(rr1, scales=list(x=list(at=seq(450000,480000,4000))),
              margin=F, cuts=200,
              col.regions = terrain.colors(350,alpha=1), 
              colorkey=list(space="bottom"),
              xlab="Easting(m)", ylab="Northing(m)")
plot(p)

The plot ends up looking like this:

levelplot

What I cannot figure out is how to increase the space between the colorkey and the x-axis such that the colorkey does not cover the x-axis label.

like image 255
Dan Avatar asked Apr 25 '15 19:04

Dan


2 Answers

Add the following:

par.settings = list(layout.heights=list(xlab.key.padding=1))

Test example:

x <- seq(pi/4, 5*pi, length.out=100)
y <- seq(pi/4, 5*pi, length.out=100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
p <- levelplot(z~x+y, data=grid,
               margin=F, cuts=200,
               par.settings=list(layout.heights=list(xlab.key.padding=1)),
               col.regions=terrain.colors(350, alpha=1), 
               colorkey=list(space="bottom"),
               xlab="Easting(m)", ylab="Northing(m)")
print(p)

levelplot

like image 152
rcs Avatar answered Sep 28 '22 08:09

rcs


A quick fix would be to add a new line to your x-label, as follows: xlab="Easting(m)\n". This will add a blank line between the x-label and the legend.

like image 23
eipi10 Avatar answered Sep 28 '22 10:09

eipi10