Warming stripes

Warming stripes được tạo ra bởi Ed Hawkins năm 2018 để trực quan hóa sự ấm lên của toàn cầu do biến đổi khí hậu (Hình 1). Ý tưởng của warming stripes cũng được áp dụng để trực quan hóa suy giảm đa dạng sinh học.

Ed Hawkins giới thiệu về warming stripes năm 2018

Hình 1: Ed Hawkins giới thiệu về warming stripes năm 2018

Trong bài viết này mình sẽ dùng warming stripes để trực quan hóa biến động nhiệt độ bề mặt nước biển (sea surface temperature anomaly) ở Central and Southern North Sea (ICES division 4bc). Mình dùng dữ liệu HadISST từ năm 1870 đến năm 2021. Code sử dụng trong bài viết được tham khảo từ đây.

Tải và xử lý dữ liệu

Dữ liệu mình sử dụng đã được cắt theo một số khu vực ở vùng biển Châu Âu từ dữ liệu gốc toàn cầu của HadISST. Dữ liệu có thể tải ở đây. Tuy nhiên, để sử dụng cho bài viết này thì mình vẫn cần lọc lấy dữ liệu Central and Southern North Sea, tính giá trị nhiệt độ trung bình cho cả khu vực theo năm, và tính biến động nhiệt độ.

# Thiết lập ban đầu
library(tidyverse)    # process data
library(lubridate)    # process date-time
library(RColorBrewer) # color palette
library(scales)       # check color 
# Tải dữ liệu
hadisst <- read_rds(file.path("./data", "hadisst_ices.rds"))

# Xử lý dữ liệu
hadisst_year <- hadisst %>%
  # lọc dữ liệu Central and Southern North Sea
  filter(IcesArea == "4bc") %>%
  # tính giá trị nhiệt độ trung bình cho cả khu vực theo năm
  group_by(Year) %>%
  summarize(temp = mean(hadisst_degC)) %>%
  # tính biến động nhiệt độ
  mutate(c.temp = as.numeric(scale(temp, scale = F))) %>%
  # thêm dữ liệu date để tiện cho việc trực quan hóa 
  mutate(date = ymd(str_c(Year, "01-01", sep = "-")))

Tạo bảng màu warming stripes

Bảng màu warming stripes bao gồm 8 màu bão hòa nhất ở sắc xanh và sắc đỏ từ bảng 9 màu đơn sắc của ColorBrewer.

stripe_red <- brewer.pal(9, "Reds")[2:9]
stripe_blue <- brewer.pal(9, "Blues")[2:9]
col_stripe <- c(rev(stripe_blue), stripe_red)

# hiển thị bảng màu
scales::show_col(col_stripe)
Bảng màu warming stripes

Hình 2: Bảng màu warming stripes

Ngoài ra để cho đẹp thì cũng cần tạo theme

theme_stripe <- theme_minimal()+
                 theme(axis.text.y = element_blank(),
                       axis.line.y = element_blank(),
                       axis.title = element_blank(),
                       panel.grid.major = element_blank(),
                       legend.title = element_blank(),
                       axis.text.x = element_text(vjust = 3),
                       panel.grid.minor = element_blank(),
                       plot.title = element_text(size = 14, face = "bold"),
                       plot.subtitle = element_text(size = 8),
                       legend.position = "bottom"
                       )

Warming stripes - Central and Southern North Sea

# thiết lập các khoảng ngắt của chú thích (legend)
# range(hadisst_year$c.temp) #-1.2 - 1.6
limits = c(-1.6, 1.6)
breaks = c(-1.6, -1, -0.5, 0, 0.5, 1, 1.6)

# warming stripes
ggplot(hadisst_year,
             aes(x = date, y = 1, fill = c.temp)) +
        geom_tile() +
           scale_x_date(date_breaks = "30 years",
                     date_labels = "%Y",
                     expand = c(0, 0)) +
           scale_y_continuous(expand = c(0, 0)) +
           scale_fill_gradientn(colors = col_stripe,
                                limits= limits,
                                breaks = breaks) +
            guides(fill = guide_colorbar(barheight = 0.5, barwidth = 10)) +
            labs(title = "Central and Southern North Sea | 1870-2021",
                 subtitle = "Data: Hadley Centre Sea Ice and Sea Surface TemperatureTemperature Analysis")+
              theme_stripe  
Warming stripes - Central and Southern North Sea

Hình 3: Warming stripes - Central and Southern North Sea

References