将标题添加到关卡颜色键 R

问题描述 投票:0回答:1

如何为

levelplot
colorkey
添加水平标题?

library(raster)
library(rasterVis)
r <- raster(ncol=10,nrow=10)
r[] <- sample(c(1:3),size=100,replace=T)
r1 <- raster(ncol=10,nrow=10)
r1[] <- sample(c(1:9),size=100,replace=T)
r2 <- raster(ncol=10,nrow=10)
r2[] <- sample(c(5:15),size=100,replace=T)
r3 <- raster(ncol=10,nrow=10)
r3[] <- sample(c(3:35),size=100,replace=T)
s <- stack(r,r1,r2,r3)

breaks <- 7
my.at <- round(seq(min(minValue(s)), max(maxValue(s)), length.out = breaks),digits=2)
myColorkey <- list(space = "bottom",title="some number of days",at=my.at,height=0.95, width=1, labels=list(at=my.at,cex=1.1))
levelplot(s,at=my.at,colorkey = myColorkey)

enter image description here

r levelplot
1个回答
0
投票

从文档中,您可以使用

title.control=
参数在颜色栏的顶部或底部设置水平标题,例如
title.control = list(side = "top")
将标题放在顶部:

library(raster)
#> Loading required package: sp
library(rasterVis)
#> Loading required package: lattice

set.seed(123)

r <- raster(ncol = 10, nrow = 10)
r[] <- sample(3, size = 100, replace = T)
r1 <- raster(ncol = 10, nrow = 10)
r1[] <- sample(9, size = 100, replace = T)
r2 <- raster(ncol = 10, nrow = 10)
r2[] <- sample(5:15, size = 100, replace = T)
r3 <- raster(ncol = 10, nrow = 10)
r3[] <- sample(3:35, size = 100, replace = T)
s <- stack(r, r1, r2, r3)

breaks <- 7
my.at <- round(seq(min(minValue(s)), max(maxValue(s)),
  length.out = breaks
), digits = 2)
myColorkey <- list(
  space = "bottom", title = "some number of days",
  at = my.at, height = 0.95, width = 1,
  labels = list(at = my.at, cex = 1.1),
  title.control = list(side = "top")
)
levelplot(s, at = my.at, colorkey = myColorkey)

© www.soinside.com 2019 - 2024. All rights reserved.