Inspired by Creating the Warming Stripes in Matplotlib
We are going to use the HadCRUT4 dataset, published by the Met Office. It uses combined sea and land surface temperatures. The dataset used for the warming stripes is the annual global average.
FIRST <- 1850
LAST <- 2020 # inclusive
# Reference period for the center of the color scale
FIRST_REFERENCE <- 1971
LAST_REFERENCE <- 2000
LIM <- 0.7 # degrees
dataset_url <- 'https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.6.0.0.annual_ns_avg.txt'
HadCRUT4 <- readr::read_table(dataset_url, col_names=F) %>% select( year=1, anomaly=2 ) %>% na.omit
# the colors in this colormap come from http://colorbrewer2.org
# the 8 more saturated colors from the 9 blues / 9 reds
# cmap <- ListedColormap([
cmap <- c( '#08306b', '#08519c', '#2171b5', '#4292c6',
'#6baed6', '#9ecae1', '#c6dbef', '#deebf7',
'#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a',
'#ef3b2c', '#cb181d', '#a50f15', '#67000d' )
HadCRUT4 %>% ggplot( aes( x=year, y=1, fill=anomaly)) +
geom_tile() +
scale_fill_gradientn(colors=cmap) +
guides( fill='none' ) +
theme( axis.line = element_blank(),
axis.title=element_blank(),
axis.ticks = element_blank(),
axis.text=element_blank(),
plot.margin = margin(0, 0, 0, 0, "null"),
plot.background = element_rect(fill = "transparent",colour = NA),
panel.spacing = margin(0, 0, 0, 0, "null"), ) +
coord_cartesian(expand = 0) + scale_x_continuous(expand=c(0,0)) + scale_y_continuous(expand=c(0,0)) + labs(x=NULL, y=NULL, title=NULL)
# col.set_array(anomaly)
# col.set_cmap(cmap)
# col.set_clim(reference - LIM, reference + LIM)
# ax.add_collection(col)