Lalantra
Lalantra

Reputation: 87

Place ticks in middle of each colors in levelplot

I am trying to place the ticks and names in middle of the each color in colorkeys but unable to do it. Is it possible to move the ticks in middle of color in levelplot?

> library (raster)
> ras <- list.files("/filepath/", pattern = "\\.tif$", full=TRUE)
> s <- stack(ras)
> levelplot(s, colorkey=list(at=seq(-3, 4, 1), labels=list(at=c(-3, -2, -1, 0, 1, 2,3, 4), labels=c("AA", "BB", "CC", "DD","EE", "FF", "GG")))

Upvotes: 1

Views: 212

Answers (1)

StupidWolf
StupidWolf

Reputation: 46938

You can try something like this:

library (raster)
library(rasterVis)

ras <- lapply(1:3,function(i){
r <- raster()
values(r) <- sample(x = 1:10,size = ncell(r),replace = TRUE)
r
})
s <- stack(ras)
levelplot(s, colorkey=list(at=seq(-3, 4, 1), 
labels=list(at=c(-2.5, -1.5, -0.5,0.5, 1.5,2.5,3.5), 
labels=c("AA", "BB", "CC", "DD","EE", "FF", "GG"))))

enter image description here

Upvotes: 1

Related Questions