r - Reverse legend in raster -


while plotting raster image, example:

library(raster)  r <- raster(nrow = 3, ncol = 3) values(r) <- 1:9  plot(r, col = terrain.colors(255)) 

enter image description here

how can legend being in ascending order, i.e. 1 (top) 9 (bottom)?

i thought of legend.args, couldn't find right arguments.

i tried bit , think i've found solution myself, though not 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, @ = seq(-10, 10, length.out = 9), labels = 9:1, las = 1) 

enter image description here

anyway, i'd appreciate other ideas!


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -