user2543622
user2543622

Reputation: 6766

R raster package plot() producing monochrome images

I would like to get monochrome images using plot function. But it keeps on producing color images. I even had monochrome images that i plotted using plot function and i got them in some weird green and orange color. How can i make plot function provide monochrome images? I tried to read about getValues function but found it difficult to understand as i am not from image analysis background. It seems that getBlocks() function returns monochrome images. But is there a way to get monochrome images using just plot function?

library(raster)
r <- raster(matrix(runif(100), 10))
plot(r)
#even below lines produce a yellow color image. i thought that they will produce a black or white square
r <- raster(matrix(rep(0,100), 10))
plot(r)

Upvotes: 3

Views: 5516

Answers (1)

Steven
Steven

Reputation: 3292

If you're looking for gray scale vector of colors, you can use gray.scale() for the col argument in plot():

library(raster)
r <- raster(matrix(rnorm(100), 10))
plot(r, col = gray.colors(10, start = 0.3, end = 0.9, gamma = 2.2, alpha = NULL))

You were getting the greens from plot() because the default for col use

rev(terrain.colors(255)) 

Upvotes: 9

Related Questions