Lalantra
Lalantra

Reputation: 87

Move the position of colorbar/ colorkeys in levelplot

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

Upvotes: 2

Views: 1146

Answers (3)

augenbrot
augenbrot

Reputation: 3

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

Upvotes: 0

Lalantra
Lalantra

Reputation: 87

@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

Upvotes: 0

Khaynes
Khaynes

Reputation: 1986

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

Upvotes: 3

Related Questions