全球异常温度可视化

全球异常温度可视化

本文是学习zonination/gisstemp的笔记。分别绘制了1880年至今每个月的异常温度热力图和每个纬度范围的异常温度热力图。

年份-月份热力图

R
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
giss.avg <- read.csv("https://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.csv", stringsAsFactors = F, skip = 1)
library(ggplot2)
library(reshape2)
library(lubridate)
library(scales)
library(viridis)
library(latex2exp)
# 简单数据整理
giss.avg <- giss.avg[, 1:13]
giss.avg <- melt(giss.avg, id = "Year")
giss.avg$value <- as.numeric(giss.avg$value)
giss.avg$variable <- as.character(giss.avg$variable)
giss.avg$variable[giss.avg$variable == "Jan"] = "1"
giss.avg$variable[giss.avg$variable == "Feb"] = "2"
giss.avg$variable[giss.avg$variable == "Mar"] = "3"
giss.avg$variable[giss.avg$variable == "Apr"] = "4"
giss.avg$variable[giss.avg$variable == "May"] = "5"
giss.avg$variable[giss.avg$variable == "Jun"] = "6"
giss.avg$variable[giss.avg$variable == "Jul"] = "7"
giss.avg$variable[giss.avg$variable == "Aug"] = "8"
giss.avg$variable[giss.avg$variable == "Sep"] = "9"
giss.avg$variable[giss.avg$variable == "Oct"] = "10"
giss.avg$variable[giss.avg$variable == "Nov"] = "11"
giss.avg$variable[giss.avg$variable == "Dec"] = "12"
giss.avg$variable <- as.numeric(giss.avg$variable)
giss.avg$date <- as.Date(paste(giss.avg$Year, formatC(giss.avg$variable, width = 2, flag = "0"), "01"), "%Y %m %e")
(p1 <- ggplot(data = giss.avg, aes(x = year(date), y = month(date))) +
geom_tile(aes(fill = value)) +
scale_fill_viridis(option = "plasma") +
scale_y_reverse(breaks = 1:12,
labels = paste0(1:12, "月")) +
scale_x_continuous(breaks = seq(1880, 2020, 20),
labels = paste0(seq(1880, 2020, 20), "年")) +
labs(title = "全球气温异常现象\n",
fill = "偏离\n均值量") +
theme_bw(base_size = 20, base_family = 'STSong') +
theme(plot.title = element_text(hjust = 0.1,
family = "STSongti-SC-Bold")) +
theme(panel.grid.minor = element_blank()) +
theme(axis.title = element_blank()) +
theme(plot.margin = grid::unit(c(0.8, 1.8, 1.8, 1.8), "cm")))
ggdraw(p1) +
draw_label("数据来源:https://data.giss.nasa.gov/", x = 0.82, y = 0.05, fontfamily = 'STSong', size = 14) +
draw_label(TeX("单位:${}^{o}C$"), x = 0.82, y = 0.9, fontfamily = 'STSong', size = 14) +
draw_image("https://www.czxa.top/images/default28.png",
x = 0.6, y = 0.02, width = 0.06, height = 0.06)

年份-纬度热力图

R
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
giss.zonal <- read.csv("https://data.giss.nasa.gov/gistemp/tabledata_v3/ZonAnn.Ts+dSST.csv",  stringsAsFactors=F)
library(ggplot2)
library(reshape2)
library(lubridate)
library(scales)
library(viridis)

giss.zonal <- giss.zonal[, c(1, 8:15)]
giss.zonal <- melt(giss.zonal, id = "Year")
giss.zonal$variable <- as.character(giss.zonal$variable)

giss.zonal$variable[giss.zonal$variable=="X64N.90N"] <- "90N - 64N"
giss.zonal$variable[giss.zonal$variable=="X44N.64N"] <- "64N - 44N"
giss.zonal$variable[giss.zonal$variable=="X24N.44N"] <- "44N - 24N"
giss.zonal$variable[giss.zonal$variable=="EQU.24N"] <- "24N - 0N"
giss.zonal$variable[giss.zonal$variable=="X24S.EQU"] <- "0S - 24S"
giss.zonal$variable[giss.zonal$variable=="X44S.24S"] <- "24S - 44S"
giss.zonal$variable[giss.zonal$variable=="X64S.44S"] <- "44S - 64S"
giss.zonal$variable[giss.zonal$variable=="X90S.64S"] <- "64S - 90S"

giss.zonal$variable <- factor(giss.zonal$variable, levels = rev(c(
"90N - 64N","64N - 44N", "44N - 24N", "24N - 0N",
"0S - 24S", "24S - 44S", "44S - 64S", "64S - 90S")))

p2 <- ggplot(giss.zonal, aes(x = Year, y = variable)) +
geom_tile(aes(fill = value)) +
scale_fill_viridis(option = "plasma",
limits = c(
min(giss.zonal$value, na.rm = T),
max(giss.zonal$value, na.rm = T)
), oob = squish) +
scale_x_continuous(breaks = seq(1880, 2020, 20),
labels = paste0(seq(1880, 2020, 20), "年")) +
labs(title = "全球温度异常现象\n",
fill = "偏离均值量") +
theme_bw(base_size = 20, base_family = 'STSong') +
theme(plot.title = element_text(hjust = 0.1,
family = "STSongti-SC-Bold")) +
theme(panel.grid.minor = element_blank()) +
theme(axis.title = element_blank()) +
theme(plot.margin = grid::unit(c(0.8, 1.8, 1.8, 1.8), "cm"))

ggdraw(p2) +
draw_label("数据来源:https://data.giss.nasa.gov/", x = 0.82, y = 0.05, fontfamily = 'STSong', size = 14) +
draw_label(TeX("单位:${}^{o}C$"), x = 0.82, y = 0.9, fontfamily = 'STSong', size = 14) +
draw_image("https://www.czxa.top/images/default28.png",
x = 0.6, y = 0.02, width = 0.06, height = 0.06)

# R

评论

Your browser is out-of-date!

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

×