如何为plotRGB和plot设置相同的outptut范围?

时间:2014-08-21 10:40:18

标签: r plot raster

使用plotplotRGB生成绘图并不会提供相同的输出范围。我想为12提供相同的范围输出。

# generate red, green, blue random 10 by 10 matrix
r <- g <- b <- raster(ncol=10, nrow=10)
values(r) <- runif(ncell(r))
values(g) <- runif(ncell(r))
values(b) <- runif(ncell(r))

rgb = rgb<-stack(r*255,g*255,b*255)

# plot red
plot(r,legend=F)
# plot RGB
plotRGB(rgb)

Result from plot the red band Result from the plotRGB

1 个答案:

答案 0 :(得分:1)

函数raster::plot想要在图中添加一个图例,因此它会在右侧保留一些空间,而plotRGB只需要完整的范围。

您可以通过将栅格添加到现有地块来解决此问题:

library(raster)

# generate red, green, blue random 10 by 10 matrix
r <- g <- b <- raster(ncol=10, nrow=10)
values(r) <- runif(ncell(r))
values(g) <- runif(ncell(r))
values(b) <- runif(ncell(r))

rgb = rgb<-stack(r*255,g*255,b*255)
par(mfrow=c(2,1))

plot(c(-180,180),c(-90,90), type='n', axes=F, xlab='', ylab='')
plotRGB(rgb,add=T)

plot(c(-180,180),c(-90,90), type='n', axes=F, xlab='', ylab='')
plot(r,add=T, legend=F)
相关问题