Last active
August 26, 2018 08:49
-
-
Save Ryo-N7/2c3d602a414ef8861d77defed5e643cc to your computer and use it in GitHub Desktop.
Bar Code Chart: Tokyo Annual Average Temperature (1876-2017)
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
# http://www.climate-lab-book.ac.uk/2018/warming-stripes/ | |
# data from: http://www.data.jma.go.jp/obd/stats/etrn/view/annually_s.php?prec_no=44&block_no=47662 | |
library(ggimage) | |
library(ggplot2) | |
library(dplyr) | |
library(tidyr) | |
library(purrr) | |
library(scales) | |
library(rvest) | |
library(stringr) | |
# Couldn't get `polite` package to work with the data.jma site... | |
url <- "http://www.data.jma.go.jp/obd/stats/etrn/view/annually_s.php?prec_no=44&block_no=47662" | |
session_jma <- url %>% | |
read_html() %>% | |
html_nodes("#tablefix1") %>% | |
.[[1]] %>% | |
html_table(fill = TRUE, header = FALSE) | |
# added in a few other variables for a closer look later on... | |
tokyo_year_avg_temp <- session_jma %>% | |
select(year = X1, avg_temp = X8, avg_high = X9, avg_low = X10, | |
high_temp = X11, low_temp = X12) %>% | |
slice(-c(1, 2, 3)) %>% | |
mutate(avg_temp = avg_temp %>% str_remove("\\]") %>% as.numeric(), | |
avg_high = avg_high %>% str_remove("\\]") %>% as.numeric(), | |
avg_low = avg_low %>% str_remove("\\]") %>% as.numeric(), | |
high_temp = high_temp %>% str_remove("\\]") %>% as.numeric(), | |
low_temp = low_temp %>% str_remove("\\]") %>% as.numeric(), | |
year = as_factor(year)) | |
# 10 Class Divergent Rd-Bu: http://colorbrewer2.org/#type=diverging&scheme=RdBu&n=10 | |
temp_cols <- rev(c('#67001f','#b2182b','#d6604d','#f4a582','#fddbc7', | |
'#d1e5f0','#92c5de','#4393c3','#2166ac','#053061')) | |
# filter out 1875 and 2018 due to uncertainties/incomplete in the measurements | |
tokyo_year_avg_temp %>% | |
filter(!year %in% c(1875, 2018)) %>% | |
ggplot(aes(x = year, fill = avg_temp)) + | |
geom_bar(position = "fill", width = 1) + | |
scale_y_continuous(expand = c(0, 0)) + | |
scale_x_discrete(expand = c(0, 0)) + | |
scale_fill_gradientn(colors = temp_cols, guide = FALSE) + | |
theme_void() + | |
theme(legend.position = "bottom") | |
ggsave(filename = "../output/tokyo_yearly_avg_temp.png", height = 6, width = 8) | |
# With title + legend | |
tokyo_year_avg_temp %>% | |
filter(!year %in% c(1875, 2018)) %>% | |
ggplot(aes(x = year, fill = avg_temp)) + | |
geom_bar(position = "fill", width = 1) + | |
scale_y_continuous(expand = c(0, 0.01)) + | |
scale_x_discrete(expand = c(0, 0)) + | |
scale_fill_gradientn(colors = temp_cols, "Average Temperature (Celsius)") + | |
labs(title = "Tokyo: Annual Average Temperature (1876-2017)") + | |
theme_void() + | |
theme(text = element_text(family = "Roboto Condensed"), | |
legend.position = "bottom", | |
legend.title = element_text()) | |
ggsave(filename = "../output/tokyo_yearly_avg_temp_LABS.png", height = 6, width = 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Avg. Temperature (Celsius) from 1876-2017
![tokyo_yearly_avg_temp](https://user-images.githubusercontent.com/19657164/44625372-63acba00-a942-11e8-88e2-99b33de1f848.png)
Range: 12.9 (Dark Blue) - 17.3 (Dark Red)