Last active
May 22, 2016 08:36
-
-
Save msjgriffiths/ba9c2173769144762bcf0f6d11220127 to your computer and use it in GitHub Desktop.
Partial Replication of Climate Radar Chart (http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/)
This file contains 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) | |
# gganimate: devtools::install_github("dgrtwo/gganimate") | |
needs(ggplot2, gganimate, dplyr, viridis) | |
# HadCRUT4.4 | |
file_url = "http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.4.0.0.monthly_ns_avg.txt" | |
if(!file.exists("data.txt")) download.file(file_url, "data.txt") | |
read.table("data.txt", "", header = F, stringsAsFactors = F) %>% | |
mutate(Date = as.Date(sprintf("%s/01", V1), "%Y/%m/%d")) %>% | |
select(Date, Median = V2) -> | |
data | |
mean_1850_1900 <- mean(filter(data, Date <= "1900-01-01")$Median) | |
p <- data %>% | |
filter(Date < "2016-01-01") %>% | |
mutate(temp = Median - mean_1850_1900, | |
Month = format(Date, "%b"), | |
Month = factor(Month, levels = month.abb), | |
Year = format(Date, "%Y")) %>% | |
ggplot(aes(x = Month, y = temp, colour = Year, group = Year, frame = Year)) + | |
geom_polygon(fill = NA, size = 1, aes(cumulative = T)) + | |
geom_text(aes(label = Year), x = -.5, y = -.7, colour = "white", size = 10) + | |
scale_y_continuous(NULL, labels = NULL) + | |
scale_x_discrete(NULL) + | |
ggtitle("Global temperature changes (1850 - 2015)") + | |
coord_polar(theta = "x") + | |
scale_color_viridis(discrete = T) + | |
theme(legend.position = "none", | |
plot.background = element_rect(fill = "#333333"), | |
panel.background = element_rect("transparent"), | |
axis.text.x = element_text(size = 16, colour = "white"), | |
panel.grid = element_line("transparent"), | |
panel.grid.major = element_line("transparent"), | |
axis.title.y = element_text(colour = "transparent"), | |
axis.title.x = element_text(colour = "transparent"), | |
plot.margin = unit(rep(.25, 4), "inches"), | |
title = element_text(colour = "white", size = 18)) | |
gg_animate(p, "chart.gif", interval = 0.2, title_frame = F) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment