红色、绿色或蓝色水平的绘图

3
有没有一种方法可以使用函数plot()绘制一个矩阵/图像,并设置红色、绿色或蓝色级别,就像颜色选项grey(level, alpha = NULL)一样?
灰度级范围在0(黑色)到1(白色)之间。
我要用RGB实现相同的效果:
- 红色级别范围在0(红色)到1(白色)之间。 - 绿色级别范围在0(绿色)到1(白色)之间。 - 蓝色级别范围在0(蓝色)到1(白色)之间。
我该怎么做?

1
你正在寻找 ?colorRamp 吗? - gung - Reinstate Monica
1个回答

5
您可以使用colorRampPalette()(将"red"替换为所需的"blue""green"):
 ## 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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接