gpt4 book ai didi

光栅中的反转图例

转载 作者:行者123 更新时间:2023-12-05 01:19:36 24 4
gpt4 key购买 nike

绘制光栅图像时,例如:

library(raster)

r <- raster(nrow = 3, ncol = 3)
values(r) <- 1:9

plot(r, col = terrain.colors(255))

enter image description here

如何让图例按升序排列,即从 1(顶部)到 9(底部)?

我想到了 legend.args,但找不到正确的参数。

最佳答案

我尝试了一下,我想我自己找到了解决方案,尽管这不是最优雅的方式。

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)

enter image description here

无论如何,我会很感激其他想法!

关于光栅中的反转图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com