Created
July 12, 2024 14:35
-
-
Save sdbernard/ccdfc6bbb1aa277040987b94717b7725 to your computer and use it in GitHub Desktop.
Global surface air temperature anomalies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(needs) | |
needs(tidyverse, readxl, googlesheets4, stringr, plotly, magrittr, janitor, RcppRoll, lubridate, ggrepel, zoo, scales, rvest, jsonlite, splitstackshape, ncdf4) | |
options(scipen = 20) | |
############# | |
############# GLOBAL TEMP | |
############# | |
#Load in data | |
global_temp_raw <- read.csv('https://sites.ecmwf.int/data/c3sci/bulletin/202406/press_release/timeseries_era5_monthly_2t_global_allmonths_up_to_june_2024.csv', comment.char = "#") | |
# Assign decades and highlight years | |
global_temp <- global_temp_raw %>% | |
select(1,6) %>% | |
rename(anomaly = ano_pi) %>% | |
mutate(month = ymd(month), | |
year = year(month), | |
new_date = month %m-% months(6), | |
month_gg = month(month), | |
decade = case_when(year < 1950 ~ "1940s", | |
year < 1960 & year >=1950 ~ "1950s", | |
year < 1970 & year >=1960 ~ "1960s", | |
year < 1980 & year >=1970 ~ "1970s", | |
year < 1990 & year >=1980 ~ "1980s", | |
year < 2000 & year >=1990 ~ "1990s", | |
year < 2010 & year >=2000 ~ "2000s", | |
year < 2020 & year >=2010 ~ "2010s", | |
year >=2020 ~ "2020s", | |
T ~ "other"), | |
highlight = case_when(year == 2023 ~ "2023", | |
year == 2024 ~ "2024", | |
year == 2016 ~ "2016", | |
year == 2015 ~ "2015", | |
T ~ "other")) | |
ggplot(global_temp, aes(month_gg, anomaly, group = year,colour = year)) + | |
geom_line() + | |
scale_x_continuous(breaks = 1:12, labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))+ | |
geom_text(data = last_month_data, aes(label = year), hjust = -0.2, size = 1) + | |
scale_color_gradient2(low = "#4393c3", mid = "#f7f7f7", high = "#d6604d", midpoint = 1980) | |
#facet_wrap(~decade) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment