如何更改rasterbrick图的主标题?

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

我有一个由六层组成的栅格砖

class : RasterBrick dimensions : 47, 89, 4183, 6 (nrow, ncol, ncell, nlayers) resolution : 0.5, 0.5 (x, y) extent : 60.75, 105.25, 15.75, 39.25 (xmin, xmax, ymin, ymax) coord. ref. : NA data source : in memory names : VegC, LittC, SoilfC, SoilsC, Total,VegCX2X0.7 min values : 0, 0, 0, 0, 0, 0 max values : 22.84560, 9.63050, 28.18740, 12.90590, 51.66701, 319.83840

但是当我绘制第六个变量VegCX2X0.7时,它显示主标题为VegCX2X0.7,但我想将其更改为“Aboveground Biomass Carbon”,因此我执行以下基本代码:

plot(try3,6, col=mycol, main=" Aboveground Biomass", legend.args=list(text='Aboveground Carbon Biomass(MgC/ha)', side=4, font=2, line=2.5, cex=0.8))

但新标题没有出现,实际上没有显示标题。我怎样才能解决这个问题?

r raster
1个回答
1
投票

总是试着想出一个可重复的例子来得到最好的答案(见here)。假设这是你的光栅brick

library(raster)

#reproducible example
set.seed(987)

# setting up list pf raster stacks
r1 <- raster(nrows = 1, ncols = 1, res = 0.5, xmn = -1.5, xmx = 1.5, ymn = -1.5, ymx = 1.5, vals = runif(36, 1, 5))
r.brk <- brick(lapply(1:6, function(i) setValues(r1,runif(ncell(r1)))))
names(r.brk) <- c("VegC",     "LittC",    "SoilfC",    "SoilsC",     "Total", "VegCX2X0.7")

你可以通过以下方式更改栅格的名称:

names(r.brk) <- c("n1",     "n2",    "n3",    "n4",     "n5", "Aboveground Biomass")
plot(r.brk) #plot them in a group by their name as main title

由于您在选择名称方面存在局限性,因此您还可以在将其作为一组绘制时更改主要内容:

plot(r.brk, main=c("n1",     "n2",    "n3",    "n4",     "n5", "Aboveground Biomass Carbon"))

或者您可以更改主图标题,同时分别绘制其中任何一个,如下所示:

plot(r.brk$Aboveground.Biomass, main="Aboveground Biomass Carbon")
© www.soinside.com 2019 - 2024. All rights reserved.