我已将多个栅格绘制到矩阵网格中,我想将绘图保存到目录中的指定文件夹中。我的绘图用于会议上的海报演示,图像需要非常清晰,分辨率为 600。
我知道如何保存 ggplot 对象,但我不知道如何使用这种 R 代码配置来保存这些图像。
当我运行函数
jpeg
的代码时,我收到此警告消息:
Warning message:
In jpeg("Raster_Layers.jpg", quality = 100, units = "px", bg = "white", :
NAs introduced by coercion
代码:
#Create an empty raster to plot the rasters
r <- raster(ncols=3, nrows=2, xmn=1, xmx=6, ymn=1, ymx=6)
r1 <- r2 <- r3 <- r4 <- r5 <- r6 <- setValues(r, rnorm(ncell(r)))
#Bind the rasters together in a matrix grid layout of three columns and 2 rows
m <- rbind(c(1, 2, 3), c(4, 5, 6))
layout(m)
#Select the name the raster layer plot and specifiy to store it in the output folder
jpeg('Raster_Layers.jpg',
quality = 100,
units = "px",
bg="white",
res=600,
height=437,
width=760,
file = "/Users/Output")
#Plot the rasters (2 rows by 3 columns) into the grid
plot(resampled_sss, main = "Mean Sea Surface Salinity (kg/m3)")
plot(resampled_sst, main = "Mean Sea Surface Temperature (°C)")
plot(resampled_chla, main = "Mean Chlorphyll-a (kg/m3)")
plot(depth, main = "Depth (m)")
plot(slope, col=rev(map.pal("viridis",100)), main="Slope (degrees°)")
plot(rugosity, col=rainbow(50), main="Rugosity (degrees°)")
dev.off()
当我尝试运行函数 png 的代码时,我收到此错误消息
#Create an empty raster to plot the rasters
r <- raster(ncols=3, nrows=2, xmn=1, xmx=6, ymn=1, ymx=6)
r1 <- r2 <- r3 <- r4 <- r5 <- r6 <- setValues(r, rnorm(ncell(r)))
#Bind the rasters together in a grid layout of three columns and 2 rows
m <- rbind(c(1, 2, 3), c(4, 5, 6))
layout(m)
options(X11.options = c("-dpi", "600"))
#Select the name the raster layer plot and specifiy to store it in the output folder
png(file = "Raster_Layers.jpg",
name.opt = ".X11.Options",
envir = .X11env,
quality = 100,
units = "px",
bg="white",
type = "quartz",
res=600,
height=437,
width=760)
错误信息:
Error: object '.X11env' not found
我绘制的栅格图层的屏幕截图:
创建 png 设备后移动布局定义,如:
library(raster)
#> Loading required package: sp
r <- raster(ncols=3, nrows=2, xmn=1, xmx=6, ymn=1, ymx=6)
r1 <- r2 <- r3 <- r4 <- r5 <- r6 <- setValues(r, rnorm(ncell(r)))
#Select the name the raster layer plot and specifiy to store it in the output folder
png(file = '~/Raster_Layers.png',
units = "px",
bg="white",
res=600,
height=3000,
width=4000)
layout(matrix(c(1,2,3,4,5,6), 2, 3, byrow=T))
plot(r1)
plot(r2)
plot(r3)
plot(r4)
plot(r5)
plot(r6)
dev.off()
#> png
#> 2
创建的图像:
创建于 2024 年 10 月 24 日,使用 reprex v2.1.0