如何更改rasterbrick图解的主要标题?

时间:2019-04-14 14:42:42

标签: r raster

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

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))

但是没有显示新的标题,实际上没有标题显示。我该如何解决?

1 个答案:

答案 0 :(得分: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")