赫罗图

赫罗图

首先需要了解一下什么是“赫罗图”?

赫罗图(Hertzsprung-Russell diagram,简写为H-R diagram或HRD)是丹麦天文学家赫茨普龙及由美国天文学家罗素分别于1911年和1913年各自独立提出的。后来的研究发现,这张图是研究恒星演化的重要工具,因此把这样一张图以当时两位天文学家的名字来命名,称为赫罗图。赫罗图是恒星的光谱类型与光度之关系图,赫罗图的纵轴是光度与绝对星等,而横轴则是光谱类型及恒星的表面温度,从左向右递减。恒星的光谱型通常可大致分为 O.B.A.F.G.K.M 七种,要记住这七个类型有一个简单的英文口诀”Oh be A Fine Girl/Guy. Kiss Me!”

这篇文章是学习zonination/h-r-diagram的笔记。

首先是准备绘制这幅图需要的数据集:
hygdata_v3-1.csv
hygdata_v3-2.csv

绘图:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
setwd("~/Desktop/赫罗图")
# 绘图主题修改
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))
}

# 读入数据
catalog <- read.csv("hygdata_v3-1.csv",
sep = ",",
stringsAsFactors = F,
header = T)
catalog <- rbind(catalog,
read.csv("hygdata_v3-2.csv",
sep = ",",
stringsAsFactors = F,
header = T))
library(ggplot2)
# 为星星闪烁设定随机数种子
catalog$randomseed <- runif(nrow(catalog), min = 0, max = 2*pi)

# 下面这个for循环是为了生成36张图片然后再合并为GIF图
for(n in seq(0, 360, 10)){
print(
ggplot(catalog, aes(ci, absmag)) +
geom_point(shape = 16,
size = 0.001,
aes(alpha = (sin(randomseed+n*pi/180)),
colour = ci)) +
scale_x_continuous(limits = c(-0.5, 2.5)) +
scale_y_reverse() +
guides(colour = F, alpha = F) +
scale_alpha_continuous(range = c(0, 1)) +
scale_color_gradientn(
colours = c("blue", "skyblue", "white", "orange", "red"),
limits = c(-0.5, 2.5)
) +
labs(title = "图:赫罗图",
subtitle = "恒星的类别",
y = "绝对星等",
x = "光谱类型(B-V)"
) +
annotate("text", x = 0, y =15,
label = "白矮星", size = 4,
hjust = 0, vjust = 0, color = "white", family = "STSong") +
annotate("text", x = 1.75, y = 12,
label = "主序带", size = 4,
hjust = 0, vjust = 0, color = "white", family = "STSong") +
annotate("text", x = 1.75, y = 0,
label = "巨星", size = 4,
hjust = 0, vjust = 0, color = "white", family = "STSong") +
annotate("text", x = 1.75, y = -10,
label = "超巨星", size = 4,
hjust = 0, vjust = 0, color = "white", family = "STSong") +
z_theme())
ggsave(paste("star_anim", formatC(n, width = 3, flag = "0"), ".png", sep = ""), height = 9, width = 6, type = "cairo-png")
print(paste(n, "of", 360, "degrees completed."))
}
rm(n)

system("convert -delay 10 star_anim*.png twinkle.gif")
system("rm star_anim*.png")

注意这是 一幅动图哦!仔细观察你会发现信息是会闪烁的!

# R

评论

Your browser is out-of-date!

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

×