我正在制作一张光栅文件中的地图。我希望我的传奇在默认情况下不在外面。我正在使用此代码:
library(raster)
library(rgdal)
library(classInt)
NDII = raster("G:\\Sheyenne\\image_differencing\\NDII\\differenced.tif")
value.vector = round(values(NDII),2)
breaks.qt = classIntervals(value.vector, n = 3, style = "quantile", intervalClosure = "right")
breaks.qt = breaks.qt$brks
breaks.qt[2] = 0
xlim = c(616768.4, 646426)
ylim = c(5130933, 5159682)
print (plot(NDII, main="NDII", breaks=breaks.qt, col = rainbow(3), axes=F, xlim=xlim, ylim=ylim))
legend("topright")
但这会返回:
答案 0 :(得分:1)
这是一个可重现的例子
r <- raster(nrows = 50, ncols = 50)
set.seed(123)
id <- sample(1:2500, 100, replace = FALSE)
r[id] <- 1
plot(r)
现在使用legend = FALSE并在
之后添加图例plot(r, legend = FALSE, col = rev(terrain.colors(2)))
legend("topright", legend = c("Absence", "Presence"), fill = rev(terrain.colors(2)))
r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r, legend = FALSE, col = rev(terrain.colors(5)))
legend("topright", fill = rev(terrain.colors(5)), legend = c("0", "20", "40", "60", "80", "100"))