[英]Reverse legend in raster
While plotting a raster image, for example: 在绘制光栅图像时,例如:
library(raster)
r <- raster(nrow = 3, ncol = 3)
values(r) <- 1:9
plot(r, col = terrain.colors(255))
How can I get the legend being in ascending order, ie from 1 (top) to 9 (bottom)? 如何使图例按升序排列,即从1(顶部)到9(底部)?
I thought of the legend.args
, but couldn't find the right arguments. 我想到了legend.args
,但找不到正确的论据。
I tried a bit and I think I've found a solution myself, even though it is not the most elegant way. 我尝试了一下,我想我自己找到了一个解决方案,即使它不是最优雅的方式。
library(raster)
r <- raster(nrow = 3, ncol = 3)
values(r) <- 1:9
par(mar = c(3, 3, 4, 3))
plot(r, col = terrain.colors(255),legend = FALSE, xlim = c(-200,200),
ylim = c(-200,200))
vz = matrix(1:100, nrow = 1)
vx = c(185, 195)
vy = seq(-10, 10, length.out = 100)
par(new = TRUE, mar = c(3, 3, 4, 3))
plot(1, xlab = "", ylab = "", axes = FALSE, type = "n",
xlim = c(-200, 180), ylim = c(-20, 20))
image(vx, vy, vz, col = rev(terrain.colors(255)), axes = FALSE,
xlab = "", ylab = "", add = TRUE)
polygon(c(185, 195, 195, 185), c(-10, -10, 10, 10))
axis(4, at = seq(-10, 10, length.out = 9), labels = 9:1, las = 1)
Anyway, I'd appreciate other ideas! 无论如何,我会欣赏其他的想法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.