宇宙年龄的计算

宇宙年龄的计算

宇宙的年龄是从大爆炸开始计算的,可以通过宇宙膨胀的速度计算宇宙的年龄,本文是学习zonination/galaxies的笔记。

首先准备绘图主题,因为是绘制星系图,所以作者设计了个比较像宇宙背景的图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(ggplot2)
z_theme <- function(){
theme_bw(base_size = 15, base_family = "STSong") +
theme(panel.background = element_rect(fill = '#000000',
color = '#000000')) +
theme(plot.background = element_rect(fill = '#000000',
color = '#000000')) +
theme(panel.border = element_rect(color = '#252525')) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank()) +
theme(legend.background = element_rect(fill = '#000000')) +
theme(legend.text = element_blank()) +
theme(legend.title = element_blank()) +
theme(legend.position = "none") +
theme(plot.title = element_text(color = '#D9D9D9', size = 20, vjust = 1.25)) +
theme(plot.subtitle = element_text(color = '#BDBDBD', size = 12, vjust = 0)) +
theme(plot.caption = element_text(color = '#BDBDBD', size = 12, vjust = 0)) +
theme(axis.ticks = element_blank()) +
theme(axis.text.x = element_text(color = '#BDBDBD', size = 14)) +
theme(axis.text.y = element_text(color = '#BDBDBD', size = 14)) +
theme(axis.title.x = element_text(color = '#BDBDBD', size = 16, vjust = 0)) +
theme(axis.title.y = element_text(color = '#BDBDBD', size = 16, vjust = 1.25))
}

还有需要一个数据集,这个数据集里面是每个星系距离地球的距离和远离地球的速度:
galaxies.csv

然后就可以绘制这两个变量的散点图了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 读入数据集
galaxies <- read.csv("galaxies.csv")
View(galaxies)
# 然后进行一些单位的转换
# 把距离转换成兆帕
galaxies$distmpc <- 10^(1+galaxies$mod0/5)/1e6
# 把兆帕转换成千米
galaxies$dist <- galaxies$distmpc * 3.085678e+13*1e6

# 使用近地、远离速度较慢的星系绘图
galaxies2 <- subset(galaxies, distmpc <= 250 & vgsr <= 15000)
ggplot(galaxies2, aes(distmpc, vgsr)) +
geom_point(shape = '.', aes(colour = vgsr)) +
scale_color_gradientn(colours = c("white", "orange", "red", "darkred")) +
geom_smooth(method = "lm", formula = y~x+0, linetype = 4, size = 0.5, se = F) +
labs(title = "图:膨胀中的宇宙",
subtitle = "斜线的斜率约等于137亿年",
x = "距离地球的距离(Mpc)",
y = "脱离地球的速度(km/s)") +
z_theme()

宇宙的年龄是这样计算出来的:

1
2
3
4
> m <- lm(dist~vgsr+0, data = galaxies2)
> (age <- m$coefficients/60/60/24/365.24)
vgsr
13773258974

下面是进行宇宙大爆炸的模拟:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 模拟宇宙大爆炸
n <- 200
bigbang <- data.frame("x" = rnorm(n), "y" = rnorm(n))
bigbang$dx <- bigbang$x*0.1 + 0.05*rnorm(n)
bigbang$dy <- bigbang$y*0.1 + 0.05*rnorm(n)
bigbang$speed <- sqrt(bigbang$dx^2 + bigbang$dy^2)
bigbang$dist <- sqrt(bigbang$x^2 + bigbang$y^2)

ggplot(bigbang) +
geom_point(aes(x, y), size = 1) +
geom_segment(color = "darkred", aes(x, y, xend = x + dx, yend = y + dy), arrow = arrow(length = unit(0.1, "cm"))) +
geom_point(aes(0, 0), color = "yellow", shape = 3) +
ggtitle("图:大爆炸后微粒的速度") + z_theme() +
theme(axis.title = element_blank()) +
theme(axis.line = element_blank()) +
theme(axis.text = element_blank())

1
2
3
4
5
6
7
ggplot(bigbang, aes(dist, speed)) +
geom_point(size = 1, aes(colour = speed)) +
geom_smooth(method = "lm", se = F, formula = y~x+0, linetype = 4, size = 1) +
ylab("微粒速度") +
xlab("距离爆炸中心的距离") +
ggtitle("图:大爆炸后微粒的速度") + z_theme() +
scale_color_gradientn(colours = c("white", "orange", "red", "darkred"))

# R

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×