如何在R中绘制图像中指定颜色

时间:2016-03-05 13:01:35

标签: r image colors

我想用-40到100的值制作图像图。下面给出了默认着色它们的图像。由于这些值不对称,因此零点呈浅蓝色。

我想将零值设为白色。正值应为暖色,最大值为深红色。负值应为冷色,深蓝色为最负值。

感谢。

library(fields)
x <- 1:100
y <- 1:200
set.seed(1)
z <- runif(20000, -40, 100)
z <- matrix(z, 100, 200)
surface <- list(x=x, y=y, z=z)
plot.surface(surface, type = "I", xlab = "x", ylab = "y")

enter image description here

1 个答案:

答案 0 :(得分:1)

library(fields)
colorTable<- designer.colors(500, c( "dark blue","white", "dark red"), 
                             x = c(0, 40, 140) / 140)
#edit / add colors as desired

plot.surface(surface, type = "I", xlab = "x", ylab = "y", 
             col = colorTable)

enter image description here