2013-12-20 135 views
0

我有一個矩陣r(光柵)。我想繪製R,這簡直可以用如何將某些值設置爲R中的特定顏色?

plot (r) 

做,但我想,以紀念20的所有值(所以這個值將不會被考慮到傳說中的比例),以紅色和通常如下繪製r。 重複的例子:

library(raster) 
r <- raster(nrows=10, ncols=10) 
r <- setValues(r, 1:ncell(r)) 
plot(r) 

這將產生這樣的:

enter image description here

回答

1

優雅是不同的,但是這是你打算做什麼?

par(mfrow=c(2,2)) 
plot(r) 
r.20 <- calc(r, fun=function(x){ x[x == 20] <- NA; return(x)}) 
as.matrix(r.20) 
plot(r.20) 
r.not20 <- calc(r, fun=function(x){ x[x != 20] <- NA; return(x)}) 
plot(r.not20, col="red") 
plot(r.20); 
par(new=TRUE) 
plot(r.not20, col="red", legend=FALSE) 

enter image description here

相關問題