如何具体控制光栅文件绘图右侧的颜色键条的大小?

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

我希望制作 netcdf 文件的等高线图。我首先提取 nc 文件并将其转换为光栅格式(更容易绘制)。绘图效果很好,但我想放大右侧颜色键栏的大小。

这是我的 R 脚本:

lapply(c("ncdf4","raster","sf","Metrics"),require,character.only=TRUE)

setwd("~/Desktop/Feb_24")

border <- read_sf("India_boundary/India_Boundary.shp")
ncfile <- nc_open("monthwise/ACCESS-CM2_historic_monmean.nc")

wsp_mod <- ncvar_get(ncfile,varid="sfcWind")

pal <- colorRampPalette(c("darkblue","blue","cyan","green","yellow","orange","red"))

for(i in seq(1:12)){
  
  r_mon <- raster(wsp_mod[,,i])
  r_mon <- t(flip(r_mon,1))
  r_mon@extent <- extent(65.125,100.125,3.125,40.125)
  r_mon <-mask(crop(r_mon,extent(border)),border)
  r_mon@title <-"Multi year monthly mean"
  
  png(filename=paste(i,"_ACCESS-CM2_historic.png"),width=1400,height=1400)
  par(mar=c(5,6,4,1)+.1)
  plot(r_mon,xlab="Longitude",ylab="Latitude",main=paste(i),cex.lab=1.3,cex.axis=1.2,cex.main=1.3,col=pal(8),breaks=c(0,1,2,3,4,5,6,7,8))
  lines(border,col="black")
  dev.off()

}

参数 cex.lab、cex.axis、cex.main 不会放大颜色键栏。我在整个文档中进行了搜索,以找到控制此大小的参数,但徒劳无功。请告诉我是否有一种方法可以专门控制颜色条的大小。

r r-raster contourf ncdf4 color-key
1个回答
0
投票

如果您使用

raster::plot()
,则使用
legend.width
参数,例如:

s <- raster::stack("download.nc")

s[[1]] |>
  raster::plot()


s[[1]] |>
  raster::plot(legend.width = 2.5)

创建于 2024-03-05,使用 reprex v2.1.0

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