【发布时间】:2016-06-28 03:21:37
【问题描述】:
我有一个多波段 rasterbrick 对象,我正在寻找一种有效的解决方案,以 .jpg 格式分别绘制和保存每个对象。 我不能使用 spplot() 或 levelplot() 因为对象有 100 层。
目前我计划将每一层编写为单独的 .tiff 并使用 Arcgis 进行绘图。 Here 是我正在处理的层。
【问题讨论】:
我有一个多波段 rasterbrick 对象,我正在寻找一种有效的解决方案,以 .jpg 格式分别绘制和保存每个对象。 我不能使用 spplot() 或 levelplot() 因为对象有 100 层。
目前我计划将每一层编写为单独的 .tiff 并使用 Arcgis 进行绘图。 Here 是我正在处理的层。
【问题讨论】:
您可以编写一个函数来保存 JPEG 图,然后使用 sapply
library(raster)
rand_raster <- function() {
r <- raster(nrows = 10, ncols = 10)
r[] <- runif(100)
r
}
s <- brick(rand_raster(), rand_raster(), rand_raster())
breaks <- seq(from = min(summary(s)["Min.", ]),
to = max(summary(s)["Max.", ]),
length.out = 5)
palette <- colorRampPalette(colors = c("blue", "red"))
cols <- palette(5)
raster_plot <- function(x, s) {
jpeg(filename = paste(names(s[[x]]), ".jpg"))
plot(s[[x]], breaks = breaks, col = cols)
dev.off()
}
sapply(1:nlayers(s), function(x) raster_plot(x, s))
【讨论】:
plot 后尝试使用scalebar 函数。你应该可以修一个比例尺。
plot 中的 breaks 参数将比例固定为全局最小值和最大值。您可以根据自己的喜好修改中断次数和颜色。