情节背景的人类色谱

Human color spectrum for plot background

我正在尝试通过 OpenWetWare (source). I generate the curves using the colourvision package. I made the color spectrum with the rainbow() palette, based on code by @baptiste found here (and repeated here) 制作一张与这张图片类似的图片。

问题与疑问 我制作的渐变与实际颜色频率不符。我怎样才能生成与实际颜色频率(例如,绿黄色区域中的 550 nm,而不是青色)重合(至少接近)的光谱。我确定 rainbow() 可能不是生成所需调色板的方法,但我不知道什么是最好的方法。

MWE

library(colourvision)
library(ggplot2)
library(grid)

gradient <- t(rev(rainbow(20))) # higher value for smoother gradient
g <- rasterGrob(gradient, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) 

human <- photor(lambda.max = c(420, 530, 560), lambda = seq(400, 700, 1))

ggplot(data = human, aes(x = Wavelength)) +
  annotation_custom(g, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
  geom_line(aes(y = lambda.max420), color = "white") +
  geom_line(aes(y = lambda.max530), color = "white") +
  geom_line(aes(y = lambda.max560), color = "white") +
  scale_x_continuous(breaks = seq(400, 700, 50)) +
  labs(x = NULL, y = NULL) # Save space for question

结果

您可以使用 photobiology 包中的 w_length2rgb

library(photobiology)

gradient <- t(w_length2rgb(400:700))

#then the rest of your code as it is

根据您的评论,为了完整起见,您还可以使用来自 cvrl.org 的数据,我认为它看起来更好...

conesdata <- read.csv("http://www.cvrl.org/database/data/cones/linss10e_5.csv")
names(conesdata) <- c("Wavelength", "Red", "Green", "Blue")
conesdata[is.na(conesdata)] <- 0
conesdata$colour <- rgb(conesdata$Red, conesdata$Green, conesdata$Blue)   
gradient <- t(conesdata$colour[conesdata$Wavelength >= 400 & conesdata$Wavelength <= 700])

#then the rest of your code as before