2

I have plotted a stack of raster using the function 'levelplot' script as below:

library(raster)
library(rasterVis)
ras <- list.files("/filepath/", pattern = "\\.tif$", full=TRUE)
s <- stack(ras)
> levelplot(s, colorkey = list(space ="bottom",height=1, width=1),
names.attr=c("2011","2012","2013", "2014")))

Figure of Levelplot

The problem with the plot is that the label of x-axis label 'Longitude' overlaps with the colorbar/ colorkeys of the plot. Is it possible to move the position of colorkeys a little below the label 'Longitude'?

Thanks

Lalantra
  • 67
  • 1
  • 11

3 Answers3

3

You can adjust this with the vjust parameter in the xlab list ...

levelplot(s, colorkey = list(space = "bottom", height = 1, width = 1),
            names.attr = c("2011", "2012", "2013", "2014"),
            xlab = list(label = "Longitude", vjust = -.2)))

Before (with dummy data): enter image description here

After: enter image description here

Khaynes
  • 1,976
  • 2
  • 15
  • 27
  • 1
    Thanks that works very well. I can't upvote your answer because I have less than 15 reputations. I am a newbie in SO.. ll' revert back to upvote when I have over 15 :) – Lalantra Jan 19 '20 at 07:21
0

@Khaynes Answer to the question:

levelplot(s, colorkey = list(space = "bottom", height = 1, width = 1),
            names.attr = c("2011", "2012", "2013", "2014"),
            xlab = list(label = "Longitude", vjust = -.2)))

The result-> enter image description here All Thanks to @Khaynes

Lalantra
  • 67
  • 1
  • 11
0

I found another solution for this problem that adds padding around the x-axis label. Just add this as additional argument to your levelplot() function and adjust the padding:

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

The source is this thread, where you can find some other ideas:

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

augenbrot
  • 3
  • 3