2016-11-10 68 views
3

儘管繪製的光柵圖像,例如:逆向圖例

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,但找不到正確的參數。

回答

0

我嘗試了一下,我想我自己找到了一個解決方案,儘管它不是最優雅的方法。

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

無論如何,我會很感激其他的想法!