运行此代码后,我没有获得Firas光谱的预期R输出

lhcgjxsq  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(124)

我正在尝试运行下面的代码,可以从https://lambda.gsfc.nasa.gov/data/cobe/firas/monopole_spec/firas_monopole_spec_v1.txt访问数据

#loading the data 
cobe <- read.table("~/Downloads/cobe.txt", quote="\"")

frequency <- (cobe$V1)*29.979
spectrum <- cobe$V2

B_f <- function(frequency, t){

h <- 6.62607015e-34
c <- 299792458
k <- 1.380649e-23
spectrum <- ((2*h*frequency^3)/c^2)/exp((h*frequency)/k*t)-1
return(spectrum * 1e-9)
}

t <- 2.725
spectrum <- B_f(frequency,t)

library(ggplot2)


ggplot(data = data.frame(frequency, spectrum)) + 
geom_line(aes(x = frequency, y = spectrum)) + 
ggtitle("Blackbody spectrum at T = 2.725K \n with data from the COBE satellite") + 
xlab("Frequency (GHz)") + ylab("Spectral Radiance (MJy/sr)") + 
theme_classic()+

geom_point(aes(x = frequency, y = spectrum), color = 'red', size = 5)

我一直得到第一张图像(直线水平图),但我期待第二张图(BB曲线)output plot [2] expected plot

vltsax25

vltsax251#

根据您提供的源代码,我认为您进行了不必要的转换:

#loading the data 
cobe <- read.table("~/Downloads/cobe.txt", quote="\"")

library(ggplot2)

ggplot(data = cobe, aes(x = V1, y = V2)) + 
  geom_line(colour = "blue") + 
  ggtitle("Blackbody spectrum at T = 2.725K \n with data from the COBE satellite") + 
  xlab("Frequency (cycles/cm)") + ylab("Spectral Radiance (MJy/sr)") + 
  theme_classic()+
  geom_point(aes(x = frequency, y = spectrum), color = 'red', size = 5)

产生一个情节,以配合您的预期形象,我想?

相关问题