r - 在 R 语言中结合栅格图例
问题描述
很抱歉,我无法解决这个明显愚蠢的问题,即使在谷歌搜索了一段时间后也是如此。让我们假设以下情况,其中我有两个重叠但值等级不同的栅格。
library(raster)
# A couple of rasters from scratch
r2 <- r1 <- raster(nrows=10, ncols=10)
r1[] <- sample(c(0:99), 100, replace = F)
r2[] <- sample(c(50:149), 100, replace = F)
par(mfrow = c(1,2))
plot(r1)
plot(r2)
如何创建相同的图,但只有一个从 0 到 149 的图例,即两个栅格的组合排名?
解决方案
根据我在上一条评论中分享的答案,您可以手动设置图例的中断和颜色。然后,您只需将该色带应用于两个绘图。这是代码和情节。
# Adjust plot margins
par(mar=c(2,2,2,5))
# Set manually the breaks
breaks = seq(0,150,25)
pal <- colorRampPalette(c("white","orange","yellow","green","forestgreen"))
plot(r1, breaks=breaks, col = pal(length(breaks)-1))
plot(r2, breaks=breaks, col = pal(length(breaks)-1))
推荐阅读
- oracle - 将所有名称提取到多行块中
- html - 我可以在 Flask 中播放 html5 中包含的视频文件吗?
- oracle - 使用 Oracle Wallet 存储对称密钥
- c# - DataGridView 中带有 textboxchanged 的搜索按钮
- node.js - 我在模态框内实现了一个视频标签。点击它,视频应该会播放。但是,就我而言,正在播放相同的视频
- ios - 试图理解 iOS 中 AutoLayout 的渲染循环
- javascript - 输入类型=范围。如何使滑块值可被 10 整除?
- python - scikit-learn Normalizer 处理稀疏矩阵
- node.js - 发出 http 或 https 请求时如何指定 ip 和主机名?
- arrays - 使用 PHP 7 的可折叠 print_r() 树(没有 preg_replace() 和 /e)