diff --git a/DESCRIPTION b/DESCRIPTION
index 473da7a..0740be6 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: hockeystick
Title: Download and Visualize Essential Climate Change Data
-Version: 0.8.4
+Version: 0.8.5
Authors@R:
person(given = "Hernando",
family = "Cortina",
@@ -11,7 +11,7 @@ Description: Provides easy access to essential climate change datasets to non-cl
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
-RoxygenNote: 7.3.1
+RoxygenNote: 7.3.2
URL: https://cortinah.github.io/hockeystick/, https://github.com/cortinah/hockeystick
BugReports: https://github.com/cortinah/hockeystick/issues
Imports: ggplot2, lubridate, tools, readr, dplyr, tidyr, patchwork, scales, rvest, tibble, treemapify, RColorBrewer, jsonlite
diff --git a/LICENSE b/LICENSE
index d4dba94..5410c94 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,2 +1,2 @@
-YEAR: 2023
+YEAR: 2024
COPYRIGHT HOLDER: Hernando Cortina
diff --git a/LICENSE.md b/LICENSE.md
index 014e91a..f3ed2c2 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
# MIT License
-Copyright (c) 2023 Hernando Cortina
+Copyright (c) 2024 Hernando Cortina
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/NAMESPACE b/NAMESPACE
index 8433463..1c95ad8 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -5,6 +5,7 @@ export(climate_grid)
export(emissions_map)
export(get_carbon)
export(get_dailytemp)
+export(get_dailytempcop)
export(get_emissions)
export(get_hurricanes)
export(get_icecurves)
@@ -19,7 +20,9 @@ export(hockeystick_cache_delete_all)
export(hockeystick_cache_details)
export(hockeystick_cache_list)
export(hockeystick_update_all)
+export(merge_carbontemp)
export(plot_carbon)
+export(plot_carbontemp)
export(plot_dailytemp)
export(plot_emissions)
export(plot_emissions_with_land)
@@ -37,6 +40,7 @@ export(plot_temp_scatter)
export(warming_stripes)
import(dplyr)
import(ggplot2)
+import(lubridate)
import(patchwork)
import(rvest)
import(tidyr)
diff --git a/NEWS.md b/NEWS.md
index f257fab..d6860f5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,87 +1,68 @@
# hockeystick 0.0.0.9000
-
* Added a `NEWS.md` file to track changes to the package.
# hockeystick 0.1.0
-
* Five datasets and warming stripes included in package
# hockeystick 0.2.0
-
* Add climate_grid() and hockeystick_update_all()
# hockeystick 0.3.0
-
* Add get_icecurves() and plot_icecurves() to visualize current and historic sea ice
# hockeystick 0.3.4
-
* Don't cache data by default, added write_cache options
# hockeystick 0.4.0
-
* Add get_temp2k() and plot_temp2k() to visualize global Common Era reconstructed temp
# hockeystick 0.5.0
-
* Add Atlantic hurricane data, get_hurricanes(), plot_hurricanes(), plot_hurricane_nrg()
# hockeystick 0.5.1
-
* Update caching approach to comply with CRAN policies
# hockeystick 0.5.2
-
* Add date/value annotations to charts
# hockeystick 0.6.0
-
* Add global emissions from GCP: get_emissions(), plot_emissions()
# hockeystick 0.6.1
-
* Fix leaving example data in cache
# hockeystick 0.6.2
-
* Update documentation to conform with R version 4.2
# hockeystick 0.6.3
-
* Add connectivity checks to conform with CRAN requirements
# hockeystick 0.7.0
-
* Added methane data and cumulative co2 emissions treemap visualization
# hockeystick 0.7.1
-
* Plot GCP emissions with land use change
# hockeystick 0.7.2
-
* url-specific connectivity checks
# hockeystick 0.7.3
-
* Fix climate grid connectivity checks
# hockeystick 0.8.0
-
* Add daily temperature data from ClimateReanalyzer.org
# hockeystick 0.8.1
-
* Select hurricane category in get_hurricanes() / Fix daily temp caching
# hockeystick 0.8.2
-
* Update new get_dailytemp() urls
# hockeystick 0.8.3
-
* Update to reflect climatereanalyzer switch to Copernicus data
# hockeystick 0.8.4
-
* Update to plot_temp_scatter() and plot_temp_monthly()
+
+# hockeystick 0.8.5
+* Add plot_carbontemp() and get_dailytemp_cop(), default to Copernicus
diff --git a/R/2kyears_temp.R b/R/2kyears_temp.R
index 62ad0d2..f548767 100644
--- a/R/2kyears_temp.R
+++ b/R/2kyears_temp.R
@@ -2,7 +2,7 @@
#'
#' Retrieves the Common Era Global Surface Temperature Reconstructions.
#' Source is PAGES2k Consortium and NOAA National Centers for Environmental Information.
-#' \url{https://www.ncei.noaa.gov/access/paleo-search/study/26872)}
+#' \url{https://www.ncei.noaa.gov/access/paleo-search/study/26872}
#'
#' @name get_temp2k
#' @param use_cache (boolean) Return cached data if available, defaults to TRUE. Use FALSE to fetch updated data.
@@ -50,7 +50,7 @@ hs_path <- tools::R_user_dir("hockeystick","cache")
if (use_cache) {
if (file.exists(file.path(hs_path,'temp2k.rds'))) return(invisible(readRDS((file.path(hs_path,'temp2k.rds'))))) }
-file_url <- 'https://www1.ncdc.noaa.gov/pub/data/paleo/pages2k/neukom2019temp/recons/Full_ensemble_median_and_95pct_range.txt'
+file_url <- 'https://www.ncei.noaa.gov/pub/data/paleo/pages2k/neukom2019temp/recons/Full_ensemble_median_and_95pct_range.txt'
connected <- .isConnected(file_url)
if (!connected) {message("Retrieving remote data requires internet connectivity."); return(invisible(NULL))}
diff --git a/R/carbon.R b/R/carbon.R
index 60c2dfc..ee2045c 100644
--- a/R/carbon.R
+++ b/R/carbon.R
@@ -47,13 +47,13 @@ if (use_cache & !write_cache) {
if (file.exists(file.path(hs_path,'maunaloa.rds'))) return(invisible(readRDS((file.path(hs_path,'maunaloa.rds')))))
}
-file_url <- 'ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt'
+file_url <- 'https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.csv'
connected <- .isConnected(file_url)
if (!connected) {message("Retrieving remote data requires internet connectivity."); return(invisible(NULL))}
dl <- tempfile()
download.file(file_url, dl)
-maunaloa <- suppressMessages( read_table(dl, col_names = FALSE, skip = 63) )
+maunaloa <- suppressMessages( read_csv(dl, col_names = FALSE, skip = 41) )
colnames(maunaloa) <- c('year', 'month', 'date', 'average', 'trend', 'ndays','stdev','unc')
maunaloa$date <- ceiling_date(ymd(paste(maunaloa$year, maunaloa$month, '01',sep='-')), unit='month')-1
diff --git a/R/daily_temp.R b/R/daily_temp.R
index 5187aa9..ea4e4a1 100644
--- a/R/daily_temp.R
+++ b/R/daily_temp.R
@@ -1,6 +1,6 @@
#' Download and plot essential climate data
#'
-#' Retrieves the daily air or sea-surface temperature data since 1979 from ClimateReanalyzer.org
+#' Retrieves the daily air or sea-surface temperature data since 1940 from ClimateReanalyzer.org
#' Source is University of Maine Climate Change Institute.
#' \url{https://climatereanalyzer.org/clim/t2_daily/}
#'
@@ -158,16 +158,17 @@ invisible(daily_temperature)
#' Download and plot essential climate data
#'
-#' Plots the daily temperatures since 1940 and current anomaly data retrieved using `get_dailytemp()` with ggplot2. The output ggplot2 object may be further modified.
+#' Plots the daily temperatures since 1940 and current anomaly data retrieved using `get_dailytempcop()` with ggplot2. The output ggplot2 object may be further modified.
#'
#'
#' @name plot_dailytemp
-#' @param dataset Name of the tibble generated by `get_dailytemp`
+#' @param dataset Name of the tibble generated by `get_dailytempcop` or `get_dailytemp`
#' @param print (boolean) Display daily temperature ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.
#' @param anomaly (boolean) Display current anomaly versus historic mean, defaults to TRUE.
#' @param maxtemp (boolean) Display current deviation versus historic max, defaults to FALSE.
#' @param current_year (numeric) Year to highlight in alternate color, defaults to current year.
#' @param title_lab (string) Title to override default chart title. Default title pulls region name from dataset attributes.
+#' @param cop (boolean) Flag for chart caption, TRUE = Copernicus, FALSE =. ClimateReanalyzer.org
#'
#' @return Invisibly returns a ggplot2 object with daily temperature anomaly chart
#'
@@ -180,7 +181,7 @@ invisible(daily_temperature)
#' @examples
#' \donttest{
#' # Fetch temperature anomaly:
-#' dailydata <- get_dailytemp()
+#' dailydata <- get_dailytempcop()
#' #
#' # Plot output using package's built-in ggplot2 defaults
#' plot_dailytemp(dailydata)
@@ -188,7 +189,7 @@ invisible(daily_temperature)
#' # Don't plot anomaly shading and highight specific year
#' plot_dailytemp(anomaly = FALSE, current_year = 2012)
#'
-#' # Or just call plot_temp(), which defaults to get_temp() dataset
+#' # Or just call plot_temp(), which defaults to get_dailytempcop() dataset
#' plot_dailytemp()
#'
#' p <- plot_dailytemp(dailydata, print = FALSE)
@@ -198,9 +199,9 @@ invisible(daily_temperature)
#'
#' @export
-plot_dailytemp <- function(dataset = get_dailytemp(), print = TRUE, anomaly = FALSE, maxtemp = FALSE,
+plot_dailytemp <- function(dataset = get_dailytempcop(), print = TRUE, anomaly = FALSE, maxtemp = FALSE,
current_year = as.numeric(substr(Sys.Date(), 1, 4)),
- title_lab = 'Daily Average Air Temperature') {
+ title_lab = 'Daily Average Air Temperature', cop=TRUE) {
if (is.null(dataset)) return(invisible(NULL))
@@ -234,9 +235,12 @@ if (title_lab == "Daily Average Air Temperature") {
# Color code notes: 'A': all years, 'M': mean, 'L': latest.
+captionsource <- if (cop) paste0('Source: EU Copernicus Climate Service\ncds.climate.copernicus.eu as of ', latest)
+ else
+ paste0('Source: Climate Change Institute, University of Maine\nClimateReanalyzer.org as of ', latest)
+
plot <- ggplot(dataset) +
geom_line(aes(x = dummy_date, y = temp, group = year, color = 'A'), alpha = 0.7) +
- scale_fill_gradientn(name = 'Anomaly (C\U00B0)', colors = RColorBrewer::brewer.pal(9, 'YlOrRd'), labels = scales::label_number(accuracy = 0.1)) +
geom_line(aes(dummy_date, mean_temp, color = 'M'), linetype = 'dashed', linewidth = 1.1) +
scale_y_continuous(n.breaks = 9) +
theme_bw(base_size = 12) +
@@ -245,7 +249,7 @@ plot <- ggplot(dataset) +
date_labels = '%b%est', date_minor_breaks = '1 month') +
labs(title = title_lab, subtitle = subtitle_lab,
y = 'Temperature (C\U00B0)',
- caption = paste0('Source: Climate Change Institute, University of Maine\nClimateReanalyzer.org as of ', latest),
+ caption = captionsource,
color = NULL) +
scale_color_manual(values = c('firebrick', 'black', 'grey'), labels = c(current_year, meanperiod, 'All years'), breaks = c('L', 'M', 'A')) +
geom_line(data = filter(dataset, year == current_year),
@@ -273,7 +277,7 @@ if (anomaly) {
labs(subtitle = subtitle_lab) }
if (maxtemp) {
- subtitle_lab <- '2-meter temperature since 1979, mean, and deviation from historic max'
+ subtitle_lab <- '2-meter temperature since 1940, mean, and deviation from historic max'
if (region == 'World (60S-60N)' | region == 'North Atlantic' | region == 'WS' | region == 'AS')
subtitle_lab <- 'Sea surface temperature since 1982, mean, and current anomaly'
@@ -297,3 +301,93 @@ if (maxtemp) {
if (print) suppressMessages( print(plot) )
invisible(plot)
}
+
+
+#' Download and plot essential climate data
+#'
+#' Retrieves the daily air temperature since 1940 from the EU Copernicus Service
+#' \url{https://cds.climate.copernicus.eu/#!/home}
+#'
+#' @name get_dailytempcop
+#' @param use_cache (boolean) Return cached data if available, defaults to TRUE. Use FALSE to fetch updated data.
+#' @param write_cache (boolean) Write data to cache, defaults to FALSE. Use TRUE to write data to cache for later use. Can also be set using options(hs_write_cache=TRUE)
+#' @param region (string) Region selection, defaults to world air temperature. Options are: World Air "W".
+#'
+#' @return Invisibly returns a tibble with the daily 2-meter air temperatures since 1940 as well as historic mean by day-of-year and current anomaly versus mean.
+#'
+#' `get_dailytempcop` invisibly returns a tibble with the daily temperatures since 1940 as well as mean by day-of-year and anomaly.
+#'
+#' Region options include world air (default).
+#' The historic daily mean-by-day period defaults to 1991-2020.
+#'
+#' Data are updated daily.
+#'
+#' @importFrom utils download.file head tail
+#' @importFrom readr parse_number
+#' @import tidyr
+#' @import dplyr
+#'
+#' @examples
+#' \donttest{
+#' # Fetch temp anomaly from cache if available:
+#' dailytemps <- get_dailytempcop()
+#' #
+#' # Force cache refresh:
+#' dailytemps <- get_dailytempcop(use_cache=FALSE)
+#' #
+#' # Review cache contents and last update dates:
+#' hockeystick_cache_details()
+#' #
+#' # Plot output using package's built-in ggplot2 settings
+#' plot_dailytemp(dailytemps) }
+#'
+#' @author Hernando Cortina, \email{hch@@alum.mit.edu}
+#' @references
+#' \itemize{
+#' \item Copernicus: \url{https://cds.climate.copernicus.eu/#!/home}
+#'
+#' Notes: daily mean surface air temperature (2-meter height) estimates from the ECMWF Reanalysis version 5 (ERA5) for the period January 1940 to present. ERA5 is a state-of-the-art numerical climate/weather modeling framework that ingests surface, radiosonde, and satellite observations to estimate the state of the atmosphere through time.
+#' ERA5 files have a horizontal grid resolution of 0.25° x 0.25° (about 31km x 31km at 45°N). Each daily temperature represents an average across all model gridcells within the defined latitude/longitude bounds for the selected domain. The means are area-weighted to account for the convergence of longitude lines at the poles
+#'
+#' }
+#'
+#' @export
+
+
+get_dailytempcop <- function(use_cache = TRUE, write_cache = getOption("hs_write_cache"), region = 'W') {
+
+ hs_path <- tools::R_user_dir("hockeystick", "cache")
+
+ if (use_cache) {
+ if (file.exists(file.path(hs_path, 'dailytempcop.rds')))
+
+ {cached_temp <- readRDS((file.path(hs_path, 'dailytempcop.rds')))
+ cached_region <- attr(cached_temp, "hs_daily_region")
+
+ if (region==cached_region) return(invisible(cached_temp)) }
+ }
+
+ file_url <- 'https://sites.ecmwf.int/data/climatepulse/data/series/era5_daily_series_2t_global.csv'
+
+ connected <- .isConnected(file_url)
+ if (!connected) {message("Retrieving remote data requires internet connectivity."); return(invisible(NULL))}
+
+ dl <- tempfile()
+ download.file(file_url, dl)
+ temp_csv <- read.csv(dl, skip = 18)
+
+ colnames(temp_csv) <- c('date', 'temp', '1991-2020 mean', 'temp_anom', 'status' )
+ temp_csv$date <- as.Date(temp_csv$date)
+ temp_csv$year <- lubridate::year(temp_csv$date)
+ temp_csv$dummy_date <- as.Date(paste("1925", lubridate::month(temp_csv$date), lubridate::day(temp_csv$date),sep = '-'))
+
+ temp_csv <- temp_csv |> filter(!is.na(dummy_date))
+ temp_csv <- temp_csv |> group_by(year) |> mutate(day_of_year = row_number()) |> ungroup()
+
+ daily_temperature <- temp_csv |> select(year, day_of_year, date, temp, `1991-2020 mean`, temp_anom, dummy_date) |> as_tibble()
+
+ attr(daily_temperature, "hs_daily_region") <- region
+
+ if (write_cache) saveRDS(daily_temperature, file.path(hs_path, 'dailytempcop.rds'))
+
+ invisible(daily_temperature) }
diff --git a/R/extra_viz.R b/R/extra_viz.R
index eeffb08..d53b795 100644
--- a/R/extra_viz.R
+++ b/R/extra_viz.R
@@ -161,12 +161,13 @@ climate_grid <- function(print = TRUE) {
#'
#' co2map <- emissions_map()
#'
-#' co2map <- emissions_map(since=2000, number=20, title="Top 20 Cumulative Emitters Since 2000")}
+#' co2map <- emissions_map(since=2000, number=20, title="Top 20 Cumulative Emitters Since 2000") }
#'
#' @author Hernando Cortina, \email{hch@@alum.mit.edu}
#'
#' @export
+
emissions_map <- function(dataset=get_emissions(), print = TRUE, since=1900, number="all",
title = substitute(paste(since,'-',to,' Cumulative '*CO[2]*" Emissions by Country"),
list(since=since, to=as.character(dataset[nrow(dataset), 2])))) {
@@ -187,3 +188,100 @@ emissions_map <- function(dataset=get_emissions(), print = TRUE, since=1900, num
if (print) suppressMessages( print(plot) )
invisible(plot)
}
+
+#' Download and plot essential climate data
+#'
+#' Merge NOAA carbon and NASA temperature datasets on common dates.
+#'
+#'
+#' @name merge_carbontemp
+#' @param carbon Name of the tibble generated by `get_carbon`
+#' @param temp Name of the tibble generated by `get_temp`
+#'
+#' @return Invisibly returns a tibble with merged datasets from `get_carbon` and `get_temp` functions.
+#'
+#' @details `merge_carbontemp` invisibly returns a tibble with the merged data from from `get_carbon` and `get_temp` functions.
+#' Tibble only includes data from dates when both datasets are available, essentially from 1960.
+#'
+#' @import lubridate
+#' @import dplyr
+#'
+#' @examples
+#' \donttest{
+#' # Create merged tibble
+#'
+#' mergedcarbontemp <- merge_carbontemp() }
+#'
+#'
+#' @author Hernando Cortina, \email{hch@@alum.mit.edu}
+#'
+#' @export
+
+merge_carbontemp <- function(carbon=get_carbon(), temp=get_temp() ) {
+
+ if (is.null(carbon) | is.null(temp)) return(invisible(NULL))
+
+temp <- temp |> select(1:13) |> tidyr::pivot_longer(cols = 2:13, names_to = 'Month', values_to = 'Anomaly') |>
+ filter(!is.na(Anomaly))
+
+temp <- temp |> mutate(Date = ceiling_date(lubridate::ym(paste(year(Year), Month)), 'month') - days(1)) |>
+ select(Date, Anomaly)
+
+carbon <- carbon |> select(Date=date, Year=year, Carbon=average)
+
+output <- inner_join(carbon, temp, by='Date')
+
+return(invisible(output)) }
+
+
+
+
+#' Download and plot essential climate data
+#'
+#' Plots the global monthly mean temperature anomaly vs atmospheric carbon with ggplot2. The output ggplot2 object may be further modified.
+#'
+#'
+#' @name plot_carbontemp
+#' @param dataset Name of the tibble generated by `merge_carbontemp`
+#' @param print (boolean) Display temperature anomaly ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.
+#'
+#' @return Invisibly returns a ggplot2 object with temperature anomaly vs carbon chart
+#'
+#' @details `plot_carbontemp` invisibly returns a ggplot2 object with a pre-defined temperature anomaly vs carbon chart using data from `merge_carbontemp`.
+#' By default the chart is also displayed. Users may further modify the output ggplot2 chart.
+#'
+#' @importFrom ggplot2 ggplot
+#'
+#' @examples
+#' \donttest{
+#' # Fetch temperature anomaly:
+#' mergedtemp <- merge_carbontemp()
+#' #
+#' # Plot output using package's built-in ggplot2 defaults
+#' plot_carbontemp(mergedtemp)
+#'
+#' # Or just call plot_carbontemp(), which defaults to merge_carbontemp() dataset
+#' plot_carbontemp()
+#'
+#' p <- plot_carbontemp(mergedtemp, print = FALSE)
+#' # Modify plot such as: p + ggplot2::labs(title='The Signature of Climate Change') }
+#'
+#' @author Hernando Cortina, \email{hch@@alum.mit.edu}
+#'
+#' @export
+
+plot_carbontemp <- function(dataset = merge_carbontemp(), print=TRUE) {
+
+ if (is.null(dataset)) return(invisible(NULL))
+
+ plot <- ggplot(dataset, aes(x=Carbon, y=Anomaly, color=Year)) + geom_point() + theme_bw() + scale_y_continuous(n.breaks = 8) +
+ scale_color_fermenter(palette = "YlOrRd", direction = 1, labels=c('1960-70s', '1980-90s', '2000-10s', '2020-40s')) +
+ theme(legend.key.height = unit(1,"cm"), legend.text = element_text(vjust = -1.5)) +
+ labs(title=expression('Global Heating and Atmospheric '*CO[2]*' Since 1959'),
+ subtitle='Monthly temperature relative to 1951-80 mean and Mauna Loa monthly mean', x=expression(title='Atmospheric '*CO[2]*' (ppm)'),
+ y='Global Temperature Anomaly (C\U00B0)', color='20-year\nperiods',
+ caption='Sources: NASA Goddard Institute for Space Studies\nNOAA/ESRL and Scripps Institution of Oceanography')
+
+ if (print) suppressMessages( print(plot) )
+ invisible(plot)
+}
diff --git a/R/globalvars.R b/R/globalvars.R
index a53f094..f7b5c21 100644
--- a/R/globalvars.R
+++ b/R/globalvars.R
@@ -2,4 +2,4 @@
utils::globalVariables(c('average', 'trend', 'year','Year', 'J-D', 'gmsl', 'method', 'month', 'name',
'age_ice', 'co2', 'land_use_change_co2', 'temp', 'value', 'size', 'measure','RevisedMajorHurricanes', 'RevisedACE',
'cumco2', 'country', 'data1', 'data366', 'day_of_year', 'dummy_date', 'linew', 'mean_temp', 'temp_anom',
- 'hurr_type', 'ice_region', 'data_source', 'Anomaly', 'Month', 'Date'))
+ 'hurr_type', 'ice_region', 'data_source', 'Anomaly', 'Month', 'Date', 'Carbon','1991-2020 mean'))
diff --git a/R/icecurves.R b/R/icecurves.R
index 5ba26e6..1a136dc 100644
--- a/R/icecurves.R
+++ b/R/icecurves.R
@@ -15,7 +15,7 @@
#' `get_icecurves` invisibly returns a tibble with time series of monthly Sea Ice Index since 1979 (in million square km).
#'
#' User may select monthly Arctic or Antarctic sea ice extent or area (in millions of square kilometers).
-#' Defaults to Arctic sea ice extent. \url{https://nsidc.org/arcticseaicenews/faq/#area_extent}
+#' Defaults to Arctic sea ice extent. \url{https://nsidc.org/sea-ice-today/about-data#area_extent}
#'
#' @importFrom utils download.file read.csv
#' @importFrom tibble tibble
diff --git a/R/instrumental_temp.R b/R/instrumental_temp.R
index 5dc4641..26e4661 100644
--- a/R/instrumental_temp.R
+++ b/R/instrumental_temp.R
@@ -112,7 +112,7 @@ if (is.null(dataset)) return(invisible(NULL))
plot <- ggplot(dataset, aes(x=Year, y=`J-D`)) +geom_line(alpha=0.75, aes(color='Annual mean')) + theme_bw(base_size=12) +
scale_x_date(name=NULL, limits=c(as.Date('1878-01-01'), ymd(max(dataset$Year))), date_breaks='15 years', date_labels='%Y') +
- scale_y_continuous(n.breaks = 8) +geom_smooth(size=1.1, se=F, span=0.3, aes(color='Loess smoothing')) +
+ scale_y_continuous(n.breaks = 9) +geom_smooth(size=1.1, se=F, span=0.3, aes(color='Loess smoothing')) +
labs(title='Global Land-Ocean Temperature Index (LOTI)', subtitle='Global surface temperature relative to 1951-1980 mean',
y='Temperature Anomaly (C\U00B0)', caption='Source: NASA Goddard Institute for Space Studies\nhttps://data.giss.nasa.gov/gistemp/') +
scale_color_manual(name=NULL, values=c('dodgerblue2','firebrick1')) +theme(legend.position = c(0.175, 0.825),legend.background=element_blank())
@@ -170,7 +170,7 @@ plot_temp_monthly <- function(dataset = get_temp(), print=TRUE) {
plot <- ggplot(dataset, aes(x=Date, y=Anomaly)) +geom_line(alpha=0.75, aes(color='Monthly mean')) + theme_bw(base_size=12) +
scale_x_date(name=NULL, limits=c(as.Date('1878-01-01'), ymd(max(dataset$Year))), date_breaks='15 years', date_labels='%Y') +
- scale_y_continuous(n.breaks = 8) +geom_smooth(size=1.1, se=F, span=0.3, aes(color='Loess smoothing')) +
+ scale_y_continuous(n.breaks = 10) +geom_smooth(size=1.1, se=F, span=0.3, aes(color='Loess smoothing')) +
labs(title='Global Land-Ocean Temperature Index (LOTI)', subtitle='Global surface temperature relative to 1951-1980 mean',
y='Temperature Anomaly (C\U00B0)', caption='Source: NASA Goddard Institute for Space Studies\nhttps://data.giss.nasa.gov/gistemp/') +
scale_color_manual(name=NULL, values=c('firebrick1','dodgerblue2')) +
@@ -190,6 +190,8 @@ plot_temp_monthly <- function(dataset = get_temp(), print=TRUE) {
#' @name plot_temp_scatter
#' @param dataset Name of the tibble generated by `get_temp`
#' @param print (boolean) Display temperature anomaly ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.
+#' @param labellatest (boolean) Display date of latest value, default = TRUE
+#' @param labelmax (boolean) Display date of max value, default = FALSE
#'
#' @return Invisibly returns a ggplot2 object with temperature anomaly chart
#'
@@ -218,7 +220,7 @@ plot_temp_monthly <- function(dataset = get_temp(), print=TRUE) {
#'
#' @export
-plot_temp_scatter <- function(dataset = get_temp(), print=TRUE) {
+plot_temp_scatter <- function(dataset = get_temp(), print=TRUE, labelmax=FALSE, labellatest=TRUE) {
if (is.null(dataset)) return(invisible(NULL))
@@ -227,9 +229,6 @@ plot_temp_scatter <- function(dataset = get_temp(), print=TRUE) {
dataset <- dataset |> mutate(Date = ceiling_date(ym(paste(year(Year), Month)), 'month') - days(1))
- dataset <- dataset |> mutate(max = ifelse(Anomaly == max(dataset$Anomaly), T, F))
- dataset <- dataset |> mutate(name = ifelse(max == T, substr(as.character(Date),1,7), ''))
-
col_strip <- RColorBrewer::brewer.pal(11, "RdBu")[-(5:7)]
plot <- ggplot(dataset, aes(x=Year, y=Anomaly, color=Anomaly)) + geom_point(size=1) + theme_bw(base_size=12) +
@@ -237,8 +236,19 @@ plot_temp_scatter <- function(dataset = get_temp(), print=TRUE) {
scale_y_continuous(n.breaks = 8) +
labs(title='Global Land-Ocean Temperature Index (LOTI)', subtitle='Global surface temperature relative to 1951-1980 mean', color='',
y='Monthly Temperature Anomaly (C\U00B0)', caption='Source: NASA Goddard Institute for Space Studies\nhttps://data.giss.nasa.gov/gistemp/') +
- theme(legend.position = c(0.09, 0.85),legend.background=element_blank() ) +
- scale_color_gradientn(colors = rev(col_strip)) + geom_text(aes(y = Anomaly+0.1, label=name), size=3)
+ theme(legend.position='inside', legend.position.inside = c(0.09, 0.85),legend.background=element_blank() ) +
+ scale_color_gradientn(colors = rev(col_strip))
+
+ if (labelmax) {
+ dataset <- dataset |> mutate(max = ifelse(Anomaly == max(dataset$Anomaly), T, F))
+ dataset <- dataset |> mutate(name = ifelse(max == T, substr(as.character(Date),1,7), ''))
+ plot <- plot + geom_text(aes(y = Anomaly+0.1, label=dataset$name), size=3) }
+
+
+ if (labellatest) {
+ if ( !exists("name", dataset) ) dataset$name <- ''
+ dataset[nrow(dataset),'name'] <- substr(as.character(pull(dataset[nrow(dataset),'Date'])), 1, 7)
+ plot <- plot + geom_text(aes(y = Anomaly+0.2, label=dataset$name), size=3) }
if (print) suppressMessages( print(plot) )
invisible(plot)
diff --git a/R/seaice.R b/R/seaice.R
index a057bc6..191c0e7 100644
--- a/R/seaice.R
+++ b/R/seaice.R
@@ -16,7 +16,7 @@
#' `get_seaice` invisibly returns a tibble with annual series of monthly Sea Ice Index since 1979 (in million square km).
#'
#' User may select Arctic or Antarctic sea ice extent or area (in millions of square kilometers) by year for a given month, specified by argument `month`.
-#' Defaults to Arctic July sea ice extent. \url{https://nsidc.org/arcticseaicenews/faq/#area_extent}
+#' Defaults to Arctic July sea ice extent. \url{https://nsidc.org/sea-ice-today/about-data#area_extent}
#'
#' @importFrom lubridate ymd ceiling_date
#' @importFrom utils download.file read.csv
diff --git a/README.Rmd b/README.Rmd
index 3f4b1cd..09b706b 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -1,180 +1,185 @@
----
-output: github_document
----
-
-
-
-```{r, include = FALSE}
-knitr::opts_chunk$set(
- collapse = TRUE,
- comment = "#>",
- fig.path = "man/figures/README-",
- out.width = "100%"
-)
-```
-
-# hockeystick
-
-
-[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
-![R-CMD-check](https://github.com/cortinah/hockeystick/workflows/R-CMD-check/badge.svg)
-[![CRAN status](https://www.r-pkg.org/badges/version/hockeystick)](https://CRAN.R-project.org/package=hockeystick)
-[![](https://cranlogs.r-pkg.org/badges/hockeystick)](https://cran.r-project.org/package=hockeystick)
-
-
-
-The goal of `hockeystick` is to make essential Global Heating datasets easily available in R to non-climate experts. `hockeystick` users can download the latest raw data from authoritative sources as well as view it via pre-defined ggplot2 charts. Datasets include atmospheric CO2 and CH4, carbon emissions, instrumental, reconstructed, and paleo ice-core temperature records, sea levels, hurricanes, and Arctic/Antarctic sea-ice.
-
-The choice of data was originally based on [Professor Stefan Rahmstorf's ](http://www.pik-potsdam.de/~stefan/) presentation on [The 5 Most Important Data Sets of Climate Science](http://www.pik-potsdam.de/~stefan/5datasets_rahmstorf.pdf). I came across this on a post on the [Open Mind blog](https://tamino.wordpress.com/2018/11/01/the-5-most-important-data-sets-of-climate-science/). I wrote my own [post](https://rethinking.rbind.io/2018/11/16/the-top-five-climate-charts-using-ggplot2/) on obtaining and visualizing this data (now out of date), which is the basis for this package. Additional datasets and visualizations have been added over The name of the package stems from the well known [hockeystick](https://en.wikipedia.org/wiki/Hockey_stick_graph) temperature chart.
-
-`hockeystick` was highlighted on the RStudio [RViews](https://rviews.rstudio.com/2021/03/19/february-2021-top-40-new-cran-packages/) blog by Joseph Rickert as one of the "Top 40" new packages on CRAN in February 2021.
-
-**New in version 0.8.0:** Daily temperature data from ClimateReanalyzer.com (see below).
-
-New in version 0.7.0: Globally averaged methane (CH~4~) concentration from NOAA.
-
-New in version 0.7.0: Cumulative emissions by country visualization.
-
-New in version 0.6.0: Global CO~2~ emissions by region and country from GCP.
-
-## Installation
-To install the latest `hockeystick` release from CRAN type:
-
-``` r
-install.packages("hockeystick")
-```
-
-
-You may alternatively install the development version from [https://github.com/cortinah/hockeystick](https://github.com/cortinah/hockeystick) with:
-
-``` r
-remotes::install_github("cortinah/hockeystick")
-```
-
-## Downloading and viewing global heating data
-
-New: Plot daily global temperatures since 1940 and current anomaly:
-
-```{r dailytemp, fig.retina=2, message=FALSE, out.width='60%', fig.asp=1.03}
-library(hockeystick)
-globaldaily <- get_dailytemp()
-plot_dailytemp(globaldaily)
-```
-
-Retrieve NOAA/ESRL Mauna Loa CO2 Observatory concentration data and plot:
-
-```{r carbon, fig.retina=2, message=FALSE, out.width='60%'}
-ml_co2 <- get_carbon()
-plot_carbon(ml_co2)
-```
-
-Retrieve GCP global CO~2~ emissions and plot:
-
-```{r emissions, out.width='60%', fig.retina=2, message=FALSE}
-emissions <- get_emissions()
-plot_emissions(emissions)
-plot_emissions_with_land(emissions)
-```
-
-Visualize cumulative emissions by country:
-```{r emissionsmap, out.width='60%', fig.retina=2}
-emissions_map()
-```
-
-Retrieve NASA/GISS global surface temperature anomaly data and plot:
-
-```{r temp, out.width='60%', fig.retina=2}
-anomaly <- get_temp()
-plot_temp(anomaly)
-```
-
-Visualize warming using Ed Hawkins styled "warming stripes":
-```{r stripes, out.width='60%', fig.retina=2}
-warming_stripes()
-```
-```{r stripes2, out.width='53%', fig.retina=2}
-warming_stripes(stripe_only = TRUE, col_strip = viridisLite::viridis(11))
-```
-
-Retrieve tide gauge and satellite sea level data and plot:
-
-```{r sl, out.width='60%', fig.retina=2}
-gmsl <- get_sealevel()
-plot_sealevel(gmsl)
-```
-
-Retrieve July annual Arctic Sea Ice Index and plot:
-
-```{r si, fig.retina=2, message=FALSE, out.width='60%', warning=FALSE}
-seaice <- get_seaice()
-plot_seaice(seaice)
-```
-
-`get_seaice()` arguments can be modified to download Antarctic sea ice, and allow any month.
-
-You can also visualize sea ice by month and year:
-
-```{r icecurves, fig.retina=2, message=FALSE, out.width='60%'}
-arcticice <- get_icecurves()
-plot_icecurves(arcticice)
-```
-
-Retrieve Common Era temperature reconstruction and plot it with instrumental record:
-
-```{r 2ktemp, out.width='60%', fig.retina=2}
-anomaly2k <- get_temp2k()
-plot_temp2k(anomaly2k)
-```
-
-Retrieve NOAA HURDAT2 hurricane data and plot:
-
-```{r hurricanes, out.width='60%', fig.retina=2, message=FALSE}
-hurricanes <- get_hurricanes()
-plot_hurricanes(hurricanes)
-plot_hurricane_nrg(hurricanes)
-```
-
-Retrieve NOAA/ESRL CH4 Globally averaged mean data and plot:
-
-```{r methane, fig.retina=2, message=FALSE, out.width='60%'}
-ch4 <- get_methane()
-plot_methane(ch4)
-```
-
-Retrieve Vostok paleo ice core data and plot:
-
-```{r paleo, out.width='60%', fig.retina=2, message=FALSE}
-vostok <- get_paleo()
-plot_paleo(vostok)
-```
-
-### Managing the cache
-By default, no climate data is cached, and all data is downloaded every time any of the `get_` functions is called. To cache data for future use, use the `write_cache = TRUE` option, available in all of the `get_` functions. To download and cache all data use `hockeystick_update_all()`. To view the files, date, and size of cached data use `hockeystick_cache_details()`. To re-download data from the source use the `use_cache = FALSE` argument in any of the `get_` functions, for example: `get_carbon(use_cache = FALSE, write_cache = TRUE)`. To delete all cached data use `hockeystick_cache_delete_all()`.
-
-Users may also cache data by default by adding `options(hs_write_cache = TRUE)`to their script or `.Rprofile` file.
-
-### All together now: climate data grid
-```{r grid, out.width='80%', fig.retina=2, warning=FALSE}
-climate_grid()
-```
-
-## Acknowledgments
-- Carbon Dioxide concentrations: Dr. Pieter Tans, NOAA/GML (https://gml.noaa.gov/ccgg/trends/) and Dr. Ralph Keeling, [Scripps Institution of Oceanography](https://scrippsco2.ucsd.edu/).
-- Global temperature anomaly: *GISS Surface Temperature Analysis (GISTEMP), version 4.* GISTEMP Team, 2020: NASA Goddard Institute for Space Studies. https://data.giss.nasa.gov/gistemp/
-- Warming Stripes design from Ed Hawkins' Climate Lab. https://www.climate-lab-book.ac.uk/2018/warming-stripes/. In addition grateful to Dr. Dominic Royé for posting his approach to plotting them using ggplot2, which `warming_stripes()` is based on. https://dominicroye.github.io/en/2018/how-to-create-warming-stripes-in-r/
-- Sea level data: [NOAA Laboratory for Satellite Altimetry (sat)](https://www.star.nesdis.noaa.gov/socd/lsa/SeaLevelRise/) and [Commonwealth Scientific and Industrial Research Organisation (tide gauges)](https://research.csiro.au/slrwavescoast/sea-level/measurements-and-data/sea-level-data/)
-- Sea Ice Index: [National Snow & Ice Data Center](https://nsidc.org/home).
-Data Archive: https://nsidc.org/data/explore-data
-- Vostok carbon dioxide and temperature data: https://data.ess-dive.lbl.gov/datasets/doi:10.3334/CDIAC/ATG.009
-- Common Era reconstructed temperature data: [PAGES2k Consortium and NOAA](https://www.ncei.noaa.gov/access/paleo-search/study/26872)).
-- Hurricanes: National Oceanic and Atmospheric Administration HURDAT Atlantic Hurricane Database [Re-analysis Project](https://www.aoml.noaa.gov/hrd/hurdat/Data_Storm.html), particularly Dr. Chris Landsea.
-- Carbon Dioxide emissions: [Global Carbon Project](https://www.globalcarbonproject.org/carbonbudget/) and [Our World In Data](https://github.com/owid/co2-data)
-- Methane: Lan, X., K.W. Thoning, and E.J. Dlugokencky, NOAA Global Monitoring Laboratory (https://gml.noaa.gov/ccgg/trends_ch4/).
-- Thank you to Dirk Eddelbuettel for providing the .isConnected function from his [tint](https://CRAN.R-project.org/package=tint) package to test for internet connectivity.
-- Thank you to Chris Campbell and Steven Bernard of the FT Climate Graphics Explained newsletter for sharing their code for climatereanalyzer.org daily temperature chart (Temperature Records Broken...Again, 9 July 2023). This code is the foundation of the get_dailytemp() and plot_dailytemp() functions.
-
-## Notes and resources
-- All data is compiled to the best of my ability from reliable and peer-reviewed sources. Please open an issue if you are aware of enhanced or additional data that may be added to the package. Building `hockeystick` is driven by my interest in tracking climate data and making it easily available to the community.
-- Here are some online resources I have found very helpful to learn mo re about climate science:
-- MIT edX Global Warming Science. https://www.edx.org/learn/global-warming/massachusetts-institute-of-technology-global-warming-science
-- SDG Academy: Climate Change: The Science and Global Impact. https://sdgacademy.org/course/climate-change-the-science-and-global-impact/
+---
+output: github_document
+---
+
+
+
+```{r, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>",
+ fig.path = "man/figures/README-",
+ out.width = "100%"
+)
+```
+
+# hockeystick
+
+
+[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
+![R-CMD-check](https://github.com/cortinah/hockeystick/workflows/R-CMD-check/badge.svg)
+[![CRAN status](https://www.r-pkg.org/badges/version/hockeystick)](https://CRAN.R-project.org/package=hockeystick)
+[![](https://cranlogs.r-pkg.org/badges/hockeystick)](https://cran.r-project.org/package=hockeystick)
+
+
+
+The goal of `hockeystick` is to make essential Global Heating datasets easily available in R to non-climate experts. `hockeystick` users can download the latest raw data from authoritative sources as well as view it via pre-defined ggplot2 charts. Datasets include atmospheric CO2 and CH4, carbon emissions, instrumental, reconstructed, and paleo ice-core temperature records, sea levels, hurricanes, and Arctic/Antarctic sea-ice.
+
+The choice of data was originally based on [Professor Stefan Rahmstorf's ](http://www.pik-potsdam.de/~stefan/) presentation on [The 5 Most Important Data Sets of Climate Science](http://www.pik-potsdam.de/~stefan/5datasets_rahmstorf.pdf). I came across this on a post on the [Open Mind blog](https://tamino.wordpress.com/2018/11/01/the-5-most-important-data-sets-of-climate-science/). I wrote my own [post](https://rethinking.rbind.io/2018/11/16/the-top-five-climate-charts-using-ggplot2/) on obtaining and visualizing this data (now out of date), which is the basis for this package. Additional datasets and visualizations have been added over The name of the package stems from the well known [hockeystick](https://en.wikipedia.org/wiki/Hockey_stick_graph) temperature chart.
+
+`hockeystick` was highlighted on the RStudio [RViews](https://rviews.rstudio.com/2021/03/19/february-2021-top-40-new-cran-packages/) blog by Joseph Rickert as one of the "Top 40" new packages on CRAN in February 2021.
+
+**New in version 0.8.0:** Daily temperature data from ClimateReanalyzer.com (see below).
+
+New in version 0.7.0: Globally averaged methane (CH~4~) concentration from NOAA.
+
+New in version 0.7.0: Cumulative emissions by country visualization.
+
+New in version 0.6.0: Global CO~2~ emissions by region and country from GCP.
+
+## Installation
+To install the latest `hockeystick` release from CRAN type:
+
+``` r
+install.packages("hockeystick")
+```
+
+
+You may alternatively install the development version from [https://github.com/cortinah/hockeystick](https://github.com/cortinah/hockeystick) with:
+
+``` r
+remotes::install_github("cortinah/hockeystick")
+```
+
+## Downloading and viewing global heating data
+
+New: Plot daily global temperatures since 1940 and current anomaly:
+
+```{r dailytemp, fig.retina=2, message=FALSE, out.width='60%', fig.asp=1.03}
+library(hockeystick)
+globaldaily <- get_dailytemp()
+plot_dailytemp(globaldaily)
+```
+
+Retrieve NOAA/ESRL Mauna Loa CO2 Observatory concentration data and plot:
+
+```{r carbon, fig.retina=2, message=FALSE, out.width='60%'}
+ml_co2 <- get_carbon()
+plot_carbon(ml_co2)
+```
+
+Retrieve GCP global CO~2~ emissions and plot:
+
+```{r emissions, out.width='65%', fig.retina=2, message=FALSE}
+emissions <- get_emissions()
+plot_emissions(emissions)
+plot_emissions_with_land(emissions)
+```
+
+Visualize cumulative emissions by country:
+```{r emissionsmap, out.width='60%', fig.retina=2}
+emissions_map()
+```
+
+Retrieve NASA/GISS global surface temperature anomaly data and plot:
+
+```{r temp, out.width='60%', fig.retina=2}
+anomaly <- get_temp()
+plot_temp(anomaly)
+```
+
+Plot relationship between temperature anomaly and carbon:
+```{r tempcarbon, out.width='60%', fig.retina=2}
+plot_carbontemp()
+```
+
+Visualize warming using Ed Hawkins styled "warming stripes":
+```{r stripes, out.width='60%', fig.retina=2}
+warming_stripes()
+```
+```{r stripes2, out.width='53%', fig.retina=2}
+warming_stripes(stripe_only = TRUE, col_strip = viridisLite::viridis(11))
+```
+
+Retrieve tide gauge and satellite sea level data and plot:
+
+```{r sl, out.width='60%', fig.retina=2}
+gmsl <- get_sealevel()
+plot_sealevel(gmsl)
+```
+
+Retrieve July annual Arctic Sea Ice Index and plot:
+
+```{r si, fig.retina=2, message=FALSE, out.width='60%', warning=FALSE}
+seaice <- get_seaice()
+plot_seaice(seaice)
+```
+
+`get_seaice()` arguments can be modified to download Antarctic sea ice, and allow any month.
+
+You can also visualize sea ice by month and year:
+
+```{r icecurves, fig.retina=2, message=FALSE, out.width='60%'}
+arcticice <- get_icecurves()
+plot_icecurves(arcticice)
+```
+
+Retrieve Common Era temperature reconstruction and plot it with instrumental record:
+
+```{r 2ktemp, out.width='60%', fig.retina=2}
+anomaly2k <- get_temp2k()
+plot_temp2k(anomaly2k)
+```
+
+Retrieve NOAA HURDAT2 hurricane data and plot:
+
+```{r hurricanes, out.width='60%', fig.retina=2, message=FALSE}
+hurricanes <- get_hurricanes()
+plot_hurricanes(hurricanes)
+plot_hurricane_nrg(hurricanes)
+```
+
+Retrieve NOAA/ESRL CH4 Globally averaged mean data and plot:
+
+```{r methane, fig.retina=2, message=FALSE, out.width='60%'}
+ch4 <- get_methane()
+plot_methane(ch4)
+```
+
+Retrieve Vostok paleo ice core data and plot:
+
+```{r paleo, out.width='60%', fig.retina=2, message=FALSE}
+vostok <- get_paleo()
+plot_paleo(vostok)
+```
+
+### Managing the cache
+By default, no climate data is cached, and all data is downloaded every time any of the `get_` functions is called. To cache data for future use, use the `write_cache = TRUE` option, available in all of the `get_` functions. To download and cache all data use `hockeystick_update_all()`. To view the files, date, and size of cached data use `hockeystick_cache_details()`. To re-download data from the source use the `use_cache = FALSE` argument in any of the `get_` functions, for example: `get_carbon(use_cache = FALSE, write_cache = TRUE)`. To delete all cached data use `hockeystick_cache_delete_all()`.
+
+Users may also cache data by default by adding `options(hs_write_cache = TRUE)`to their script or `.Rprofile` file.
+
+### All together now: climate data grid
+```{r grid, out.width='80%', fig.retina=2, warning=FALSE}
+climate_grid()
+```
+
+## Acknowledgments
+- Carbon Dioxide concentrations: Dr. Pieter Tans, NOAA/GML (https://gml.noaa.gov/ccgg/trends/) and Dr. Ralph Keeling, [Scripps Institution of Oceanography](https://scrippsco2.ucsd.edu/).
+- Global temperature anomaly: *GISS Surface Temperature Analysis (GISTEMP), version 4.* GISTEMP Team, 2020: NASA Goddard Institute for Space Studies. https://data.giss.nasa.gov/gistemp/
+- Warming Stripes design from Ed Hawkins' Climate Lab. https://www.climate-lab-book.ac.uk/2018/warming-stripes/. In addition grateful to Dr. Dominic Royé for posting his approach to plotting them using ggplot2, which `warming_stripes()` is based on. https://dominicroye.github.io/en/2018/how-to-create-warming-stripes-in-r/
+- Sea level data: [NOAA Laboratory for Satellite Altimetry (sat)](https://www.star.nesdis.noaa.gov/socd/lsa/SeaLevelRise/) and [Commonwealth Scientific and Industrial Research Organisation (tide gauges)](https://research.csiro.au/slrwavescoast/sea-level/measurements-and-data/sea-level-data/)
+- Sea Ice Index: [National Snow & Ice Data Center](https://nsidc.org/home).
+Data Archive: https://nsidc.org/data/explore-data
+- Vostok carbon dioxide and temperature data: https://data.ess-dive.lbl.gov/datasets/doi:10.3334/CDIAC/ATG.009
+- Common Era reconstructed temperature data: [PAGES2k Consortium and NOAA](https://www.ncei.noaa.gov/access/paleo-search/study/26872)).
+- Hurricanes: National Oceanic and Atmospheric Administration HURDAT Atlantic Hurricane Database [Re-analysis Project](https://www.aoml.noaa.gov/hrd/hurdat/Data_Storm.html), particularly Dr. Chris Landsea.
+- Carbon Dioxide emissions: [Global Carbon Project](https://www.globalcarbonproject.org/carbonbudget/) and [Our World In Data](https://github.com/owid/co2-data)
+- Methane: Lan, X., K.W. Thoning, and E.J. Dlugokencky, NOAA Global Monitoring Laboratory (https://gml.noaa.gov/ccgg/trends_ch4/).
+- Thank you to Dirk Eddelbuettel for providing the .isConnected function from his [tint](https://CRAN.R-project.org/package=tint) package to test for internet connectivity.
+- Thank you to Chris Campbell and Steven Bernard of the FT Climate Graphics Explained newsletter for sharing their code for climatereanalyzer.org daily temperature chart (Temperature Records Broken...Again, 9 July 2023). This code is the foundation of the get_dailytemp() and plot_dailytemp() functions.
+
+## Notes and resources
+- All data is compiled to the best of my ability from reliable and peer-reviewed sources. Please open an issue if you are aware of enhanced or additional data that may be added to the package. Building `hockeystick` is driven by my interest in tracking climate data and making it easily available to the community.
+- Here are some online resources I have found very helpful to learn mo re about climate science:
+- MIT edX Global Warming Science. https://www.edx.org/learn/global-warming/massachusetts-institute-of-technology-global-warming-science
+- SDG Academy: Climate Change: The Science and Global Impact. https://sdgacademy.org/course/climate-change-the-science-and-global-impact/
diff --git a/README.md b/README.md
index 8b445b2..9c323ec 100644
--- a/README.md
+++ b/README.md
@@ -96,13 +96,13 @@ emissions <- get_emissions()
plot_emissions(emissions)
```
-
+
``` r
plot_emissions_with_land(emissions)
```
-
+
Visualize cumulative emissions by country:
@@ -121,6 +121,14 @@ plot_temp(anomaly)
+Plot relationship between temperature anomaly and carbon:
+
+``` r
+plot_carbontemp()
+```
+
+
+
Visualize warming using Ed Hawkins styled “warming stripes”:
``` r
@@ -139,11 +147,10 @@ Retrieve tide gauge and satellite sea level data and plot:
``` r
gmsl <- get_sealevel()
+#> Retrieving remote data requires internet connectivity.
plot_sealevel(gmsl)
```
-
-
Retrieve July annual Arctic Sea Ice Index and plot:
``` r
@@ -228,10 +235,9 @@ Users may also cache data by default by adding
``` r
climate_grid()
+#> Retrieving remote data requires internet connectivity.
```
-
-
## Acknowledgments
- Carbon Dioxide concentrations: Dr. Pieter Tans, NOAA/GML
diff --git a/cran-comments.md b/cran-comments.md
index b6a5ffe..15cf197 100644
--- a/cran-comments.md
+++ b/cran-comments.md
@@ -1,6 +1,6 @@
## Test environments:
-* local macOS install, R 4.3.3
+* local macOS install, R 4.4.2
* GitHub Actions: ubuntu-latest (oldrel-1, release, and devel), macOS-latest (release), windows-latest (release)
diff --git a/inst/WORDLIST b/inst/WORDLIST
index 158eee3..254de38 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -74,12 +74,14 @@ Scripps
TOPEX
Tellus
Thoning
+Tibble
Vostok
WRL
WS
Waterman
Zyss
al
+carbontemp
climatereanalyzer
config
dailytemp
diff --git a/man/emissions_map.Rd b/man/emissions_map.Rd
index 783e887..5cd8cbb 100644
--- a/man/emissions_map.Rd
+++ b/man/emissions_map.Rd
@@ -41,7 +41,7 @@ By default the chart is also displayed. Users may further modify the output ggpl
co2map <- emissions_map()
-co2map <- emissions_map(since=2000, number=20, title="Top 20 Cumulative Emitters Since 2000")}
+co2map <- emissions_map(since=2000, number=20, title="Top 20 Cumulative Emitters Since 2000") }
}
\author{
diff --git a/man/figures/README-carbon-1.png b/man/figures/README-carbon-1.png
index f285e0d..5dbe2af 100644
Binary files a/man/figures/README-carbon-1.png and b/man/figures/README-carbon-1.png differ
diff --git a/man/figures/README-dailytemp-1.png b/man/figures/README-dailytemp-1.png
index 13e4343..82c9280 100644
Binary files a/man/figures/README-dailytemp-1.png and b/man/figures/README-dailytemp-1.png differ
diff --git a/man/figures/README-emissions-1.png b/man/figures/README-emissions-1.png
index 9ed76d6..d5ed3b3 100644
Binary files a/man/figures/README-emissions-1.png and b/man/figures/README-emissions-1.png differ
diff --git a/man/figures/README-emissions-2.png b/man/figures/README-emissions-2.png
index 28947e3..d7b2e03 100644
Binary files a/man/figures/README-emissions-2.png and b/man/figures/README-emissions-2.png differ
diff --git a/man/figures/README-emissionsmap-1.png b/man/figures/README-emissionsmap-1.png
index 38aaadf..2cc21c6 100644
Binary files a/man/figures/README-emissionsmap-1.png and b/man/figures/README-emissionsmap-1.png differ
diff --git a/man/figures/README-hurricanes-1.png b/man/figures/README-hurricanes-1.png
index 46f4c81..fd8fdb3 100644
Binary files a/man/figures/README-hurricanes-1.png and b/man/figures/README-hurricanes-1.png differ
diff --git a/man/figures/README-hurricanes-2.png b/man/figures/README-hurricanes-2.png
index ef799ac..2b38791 100644
Binary files a/man/figures/README-hurricanes-2.png and b/man/figures/README-hurricanes-2.png differ
diff --git a/man/figures/README-icecurves-1.png b/man/figures/README-icecurves-1.png
index 1830931..485a727 100644
Binary files a/man/figures/README-icecurves-1.png and b/man/figures/README-icecurves-1.png differ
diff --git a/man/figures/README-methane-1.png b/man/figures/README-methane-1.png
index c7c5c87..f0f12ba 100644
Binary files a/man/figures/README-methane-1.png and b/man/figures/README-methane-1.png differ
diff --git a/man/figures/README-si-1.png b/man/figures/README-si-1.png
index 789239d..96dfc78 100644
Binary files a/man/figures/README-si-1.png and b/man/figures/README-si-1.png differ
diff --git a/man/figures/README-stripes-1.png b/man/figures/README-stripes-1.png
index 765e838..e858d8f 100644
Binary files a/man/figures/README-stripes-1.png and b/man/figures/README-stripes-1.png differ
diff --git a/man/figures/README-stripes2-1.png b/man/figures/README-stripes2-1.png
index 5c02463..cd7bff6 100644
Binary files a/man/figures/README-stripes2-1.png and b/man/figures/README-stripes2-1.png differ
diff --git a/man/figures/README-temp-1.png b/man/figures/README-temp-1.png
index 3226cb5..01c53c8 100644
Binary files a/man/figures/README-temp-1.png and b/man/figures/README-temp-1.png differ
diff --git a/man/figures/README-tempcarbon-1.png b/man/figures/README-tempcarbon-1.png
new file mode 100644
index 0000000..b80c5fb
Binary files /dev/null and b/man/figures/README-tempcarbon-1.png differ
diff --git a/man/get_dailytemp.Rd b/man/get_dailytemp.Rd
index 551c503..09c0031 100644
--- a/man/get_dailytemp.Rd
+++ b/man/get_dailytemp.Rd
@@ -34,7 +34,7 @@ The historic daily mean-by-day period defaults to 1979-2000. This range can be o
Data are updated daily. For day-of-year mean removes observations from February 29 on leap years.
}
\description{
-Retrieves the daily air or sea-surface temperature data since 1979 from ClimateReanalyzer.org
+Retrieves the daily air or sea-surface temperature data since 1940 from ClimateReanalyzer.org
Source is University of Maine Climate Change Institute.
\url{https://climatereanalyzer.org/clim/t2_daily/}
}
diff --git a/man/get_dailytempcop.Rd b/man/get_dailytempcop.Rd
new file mode 100644
index 0000000..0ff06b0
--- /dev/null
+++ b/man/get_dailytempcop.Rd
@@ -0,0 +1,60 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/daily_temp.R
+\name{get_dailytempcop}
+\alias{get_dailytempcop}
+\title{Download and plot essential climate data}
+\usage{
+get_dailytempcop(
+ use_cache = TRUE,
+ write_cache = getOption("hs_write_cache"),
+ region = "W"
+)
+}
+\arguments{
+\item{use_cache}{(boolean) Return cached data if available, defaults to TRUE. Use FALSE to fetch updated data.}
+
+\item{write_cache}{(boolean) Write data to cache, defaults to FALSE. Use TRUE to write data to cache for later use. Can also be set using options(hs_write_cache=TRUE)}
+
+\item{region}{(string) Region selection, defaults to world air temperature. Options are: World Air "W".}
+}
+\value{
+Invisibly returns a tibble with the daily 2-meter air temperatures since 1940 as well as historic mean by day-of-year and current anomaly versus mean.
+
+\code{get_dailytempcop} invisibly returns a tibble with the daily temperatures since 1940 as well as mean by day-of-year and anomaly.
+
+Region options include world air (default).
+The historic daily mean-by-day period defaults to 1991-2020.
+
+Data are updated daily.
+}
+\description{
+Retrieves the daily air temperature since 1940 from the EU Copernicus Service
+\url{https://cds.climate.copernicus.eu/#!/home}
+}
+\examples{
+\donttest{
+# Fetch temp anomaly from cache if available:
+dailytemps <- get_dailytempcop()
+#
+# Force cache refresh:
+dailytemps <- get_dailytempcop(use_cache=FALSE)
+#
+# Review cache contents and last update dates:
+hockeystick_cache_details()
+#
+# Plot output using package's built-in ggplot2 settings
+plot_dailytemp(dailytemps) }
+
+}
+\references{
+\itemize{
+\item Copernicus: \url{https://cds.climate.copernicus.eu/#!/home}
+
+Notes: daily mean surface air temperature (2-meter height) estimates from the ECMWF Reanalysis version 5 (ERA5) for the period January 1940 to present. ERA5 is a state-of-the-art numerical climate/weather modeling framework that ingests surface, radiosonde, and satellite observations to estimate the state of the atmosphere through time.
+ERA5 files have a horizontal grid resolution of 0.25° x 0.25° (about 31km x 31km at 45°N). Each daily temperature represents an average across all model gridcells within the defined latitude/longitude bounds for the selected domain. The means are area-weighted to account for the convergence of longitude lines at the poles
+
+}
+}
+\author{
+Hernando Cortina, \email{hch@alum.mit.edu}
+}
diff --git a/man/get_icecurves.Rd b/man/get_icecurves.Rd
index 504db01..6762f64 100644
--- a/man/get_icecurves.Rd
+++ b/man/get_icecurves.Rd
@@ -26,7 +26,7 @@ Invisibly returns a tibble with the series of monthly Sea Ice Index since 1979 (
\code{get_icecurves} invisibly returns a tibble with time series of monthly Sea Ice Index since 1979 (in million square km).
User may select monthly Arctic or Antarctic sea ice extent or area (in millions of square kilometers).
-Defaults to Arctic sea ice extent. \url{https://nsidc.org/arcticseaicenews/faq/#area_extent}
+Defaults to Arctic sea ice extent. \url{https://nsidc.org/sea-ice-today/about-data#area_extent}
}
\description{
Retrieves Arctic or Antarctic monthly Sea Ice Index time series (in million square km).
diff --git a/man/get_seaice.Rd b/man/get_seaice.Rd
index 2ec4d2f..ec405e8 100644
--- a/man/get_seaice.Rd
+++ b/man/get_seaice.Rd
@@ -29,7 +29,7 @@ Invisibly returns a tibble with the annual series of monthly Sea Ice Index since
\code{get_seaice} invisibly returns a tibble with annual series of monthly Sea Ice Index since 1979 (in million square km).
User may select Arctic or Antarctic sea ice extent or area (in millions of square kilometers) by year for a given month, specified by argument \code{month}.
-Defaults to Arctic July sea ice extent. \url{https://nsidc.org/arcticseaicenews/faq/#area_extent}
+Defaults to Arctic July sea ice extent. \url{https://nsidc.org/sea-ice-today/about-data#area_extent}
}
\description{
Retrieves Arctic or Antarctic annual Sea Ice Index (in million square km).
diff --git a/man/get_temp2k.Rd b/man/get_temp2k.Rd
index 76fdbde..ea5632d 100644
--- a/man/get_temp2k.Rd
+++ b/man/get_temp2k.Rd
@@ -24,7 +24,7 @@ Methodology described in PAGES2k (2019) \url{https://www.nature.com/articles/s41
\description{
Retrieves the Common Era Global Surface Temperature Reconstructions.
Source is PAGES2k Consortium and NOAA National Centers for Environmental Information.
-\url{https://www.ncei.noaa.gov/access/paleo-search/study/26872)}
+\url{https://www.ncei.noaa.gov/access/paleo-search/study/26872}
}
\examples{
\donttest{
diff --git a/man/merge_carbontemp.Rd b/man/merge_carbontemp.Rd
new file mode 100644
index 0000000..d8a2ac3
--- /dev/null
+++ b/man/merge_carbontemp.Rd
@@ -0,0 +1,34 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/extra_viz.R
+\name{merge_carbontemp}
+\alias{merge_carbontemp}
+\title{Download and plot essential climate data}
+\usage{
+merge_carbontemp(carbon = get_carbon(), temp = get_temp())
+}
+\arguments{
+\item{carbon}{Name of the tibble generated by \code{get_carbon}}
+
+\item{temp}{Name of the tibble generated by \code{get_temp}}
+}
+\value{
+Invisibly returns a tibble with merged datasets from \code{get_carbon} and \code{get_temp} functions.
+}
+\description{
+Merge NOAA carbon and NASA temperature datasets on common dates.
+}
+\details{
+\code{merge_carbontemp} invisibly returns a tibble with the merged data from from \code{get_carbon} and \code{get_temp} functions.
+Tibble only includes data from dates when both datasets are available, essentially from 1960.
+}
+\examples{
+\donttest{
+# Create merged tibble
+
+mergedcarbontemp <- merge_carbontemp() }
+
+
+}
+\author{
+Hernando Cortina, \email{hch@alum.mit.edu}
+}
diff --git a/man/plot_carbontemp.Rd b/man/plot_carbontemp.Rd
new file mode 100644
index 0000000..7819909
--- /dev/null
+++ b/man/plot_carbontemp.Rd
@@ -0,0 +1,41 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/extra_viz.R
+\name{plot_carbontemp}
+\alias{plot_carbontemp}
+\title{Download and plot essential climate data}
+\usage{
+plot_carbontemp(dataset = merge_carbontemp(), print = TRUE)
+}
+\arguments{
+\item{dataset}{Name of the tibble generated by \code{merge_carbontemp}}
+
+\item{print}{(boolean) Display temperature anomaly ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.}
+}
+\value{
+Invisibly returns a ggplot2 object with temperature anomaly vs carbon chart
+}
+\description{
+Plots the global monthly mean temperature anomaly vs atmospheric carbon with ggplot2. The output ggplot2 object may be further modified.
+}
+\details{
+\code{plot_carbontemp} invisibly returns a ggplot2 object with a pre-defined temperature anomaly vs carbon chart using data from \code{merge_carbontemp}.
+By default the chart is also displayed. Users may further modify the output ggplot2 chart.
+}
+\examples{
+\donttest{
+# Fetch temperature anomaly:
+mergedtemp <- merge_carbontemp()
+#
+# Plot output using package's built-in ggplot2 defaults
+plot_carbontemp(mergedtemp)
+
+# Or just call plot_carbontemp(), which defaults to merge_carbontemp() dataset
+plot_carbontemp()
+
+p <- plot_carbontemp(mergedtemp, print = FALSE)
+# Modify plot such as: p + ggplot2::labs(title='The Signature of Climate Change') }
+
+}
+\author{
+Hernando Cortina, \email{hch@alum.mit.edu}
+}
diff --git a/man/plot_dailytemp.Rd b/man/plot_dailytemp.Rd
index c62ddee..f264084 100644
--- a/man/plot_dailytemp.Rd
+++ b/man/plot_dailytemp.Rd
@@ -5,16 +5,17 @@
\title{Download and plot essential climate data}
\usage{
plot_dailytemp(
- dataset = get_dailytemp(),
+ dataset = get_dailytempcop(),
print = TRUE,
anomaly = FALSE,
maxtemp = FALSE,
current_year = as.numeric(substr(Sys.Date(), 1, 4)),
- title_lab = "Daily Average Air Temperature"
+ title_lab = "Daily Average Air Temperature",
+ cop = TRUE
)
}
\arguments{
-\item{dataset}{Name of the tibble generated by \code{get_dailytemp}}
+\item{dataset}{Name of the tibble generated by \code{get_dailytempcop} or \code{get_dailytemp}}
\item{print}{(boolean) Display daily temperature ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.}
@@ -25,12 +26,14 @@ plot_dailytemp(
\item{current_year}{(numeric) Year to highlight in alternate color, defaults to current year.}
\item{title_lab}{(string) Title to override default chart title. Default title pulls region name from dataset attributes.}
+
+\item{cop}{(boolean) Flag for chart caption, TRUE = Copernicus, FALSE =. ClimateReanalyzer.org}
}
\value{
Invisibly returns a ggplot2 object with daily temperature anomaly chart
}
\description{
-Plots the daily temperatures since 1940 and current anomaly data retrieved using \code{get_dailytemp()} with ggplot2. The output ggplot2 object may be further modified.
+Plots the daily temperatures since 1940 and current anomaly data retrieved using \code{get_dailytempcop()} with ggplot2. The output ggplot2 object may be further modified.
}
\details{
\code{plot_temp} invisibly returns a ggplot2 object with a pre-defined daily temperature anomaly chart using data from \code{get_dailytemp}.
@@ -39,7 +42,7 @@ By default the chart is also displayed. Plots one line per year, as well as mean
\examples{
\donttest{
# Fetch temperature anomaly:
-dailydata <- get_dailytemp()
+dailydata <- get_dailytempcop()
#
# Plot output using package's built-in ggplot2 defaults
plot_dailytemp(dailydata)
@@ -47,7 +50,7 @@ plot_dailytemp(dailydata)
# Don't plot anomaly shading and highight specific year
plot_dailytemp(anomaly = FALSE, current_year = 2012)
-# Or just call plot_temp(), which defaults to get_temp() dataset
+# Or just call plot_temp(), which defaults to get_dailytempcop() dataset
plot_dailytemp()
p <- plot_dailytemp(dailydata, print = FALSE)
diff --git a/man/plot_temp_scatter.Rd b/man/plot_temp_scatter.Rd
index 02ac95f..73968d0 100644
--- a/man/plot_temp_scatter.Rd
+++ b/man/plot_temp_scatter.Rd
@@ -4,12 +4,21 @@
\alias{plot_temp_scatter}
\title{Download and plot essential climate data}
\usage{
-plot_temp_scatter(dataset = get_temp(), print = TRUE)
+plot_temp_scatter(
+ dataset = get_temp(),
+ print = TRUE,
+ labelmax = FALSE,
+ labellatest = TRUE
+)
}
\arguments{
\item{dataset}{Name of the tibble generated by \code{get_temp}}
\item{print}{(boolean) Display temperature anomaly ggplot2 chart, defaults to TRUE. Use FALSE to not display chart.}
+
+\item{labelmax}{(boolean) Display date of max value, default = FALSE}
+
+\item{labellatest}{(boolean) Display date of latest value, default = TRUE}
}
\value{
Invisibly returns a ggplot2 object with temperature anomaly chart