如何绘制波长增加的波?

How to graph a wave with increasing wavelengths?

我在看一堆电磁波谱图,发现它们显示的波与图中给定的波长实际上并不对应。例如,红外波的波长 (lambda = 800 nm) 应该比 X 射线的波长 (lambda = 1 nm) 长 800 倍。

如何在 r 中绘制波,使波长与指定波长成比例增加?即 f(x) = lambda 和 f(n * x) = n * lambda

只是电磁频谱一小部分的简单示例:

library(ggplot2)

# Make a simple dataset
max.x <- 800 # Maximum wavelength in nanometers (nm) to show
steps <- 10000 # More steps make plotting smooter

waveforms <- as.data.frame(matrix(data=NA, nrow=steps+1, ncol=2, dimnames=list(NULL, c("x", "y"))))
waveforms$x <- seq(0,max.x, by=max.x/steps)


# We can make a wave with periods that increase easily
waveforms$y <- sin(sqrt(waveforms$x))

ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")

...但只要观察图表,光谱低端的波长不会比高端波长短 800 倍。使波长成正比的实际公式是什么?

我认为你需要波长倒数的累加和(显然你必须跳过 0,否则你的累加和将是无限的):

waveforms$y <- c(0, sin(cumsum(1 / waveforms$x[-1])))


ggplot()+
  geom_line(data=waveforms, aes(x=x, y=y), color="red")+
  scale_x_continuous("Wavelength in nanometers (nm)")