3
votes

Is there a way to plot a matrix/image using the function plot() with red or green or blue levels, just like the color option grey(level, alpha = NULL)?

The grey levels range between 0(black) and 1(white).

I am looking for the same thing with RGB:

  • Red levels would range between 0(red) and 1(white).
  • Green levels would range between 0(green) and 1(white).
  • Blue levels would range between 0(blue) and 1(white).

How can I do this?

1
Are you searching for ?colorRamp?gung - Reinstate Monica

1 Answers

5
votes

You could use colorRampPalette() (replacing "red" with "blue" or "green" as desired):

 ## Matrix from ?image
 x <- y <- seq(-4*pi, 4*pi, len = 27)
 r <- sqrt(outer(x^2, y^2, "+"))

 ## Plot it using a palette of your choice
 image(z = z <- cos(r^2)*exp(-r/6), 
       col  = colorRampPalette(c("white", "red"))(64))

enter image description here