Skip to content

Instantly share code, notes, and snippets.

@ajstewartlang
Last active January 17, 2020 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajstewartlang/909c344a13e6b0b92d7bcc1bef913d6a to your computer and use it in GitHub Desktop.
Save ajstewartlang/909c344a13e6b0b92d7bcc1bef913d6a to your computer and use it in GitHub Desktop.
Tidy_Tuesday_2020_07_01
library(tidyverse)
library(mapdata)
library(ggthemes)
library(patchwork)
# read in various data files
rainfall <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/rainfall.csv')
temperature <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/temperature.csv')
nasa_fire <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-07/MODIS_C6_Australia_and_New_Zealand_7d.csv')
# co-ordinates for the arrow
arrow_data_temp <- tibble(x1 = 1932, x2 = 1932, y1 = 18, y2 = 16.7)
temperature_plot <- temperature %>%
separate(col = date, into = c("Year", "Month", "Day"), sep = "-") %>%
mutate(Year = as.integer(Year)) %>%
filter(!is.na(Year) & !is.na(temperature)) %>%
group_by(Year) %>%
summarise(Average_temp = mean(temperature)) %>%
ggplot(aes(x = Year, y = Average_temp)) +
geom_point(size = 2) +
geom_hline(aes(yintercept = 16.6), size = 1.5, colour = "gray20", linetype = "dashed", alpha = .5) +
geom_smooth(colour = "red", se = FALSE, size = 1.5) +
theme(axis.text.x = element_text(angle = 90)) +
labs(y = "Average Temperature (c)") +
theme_economist() +
theme(text = element_text(size = 12)) +
annotate("text", x = 1933, y = 18.7, size = 4, color = "gray20",
label = "Long term average\n16.6 degrees (c)") +
geom_curve(data = arrow_data_temp, aes(x = x1, y = y1, xend = x2, yend = y2),
arrow = arrow(length = unit(0.2, "cm")), size = 0.5,
color = "gray20", curvature = -0.3)
australia <- map_data("world") %>% filter(region == "Australia")
fire_plot <- nasa_fire %>%
filter(longitude < 155) %>%
filter(latitude < 0) %>%
filter(!is.na(brightness)) %>%
mutate(brightness = sort(brightness)) %>%
ggplot(aes(x = longitude, y = latitude)) +
geom_point(aes(colour = brightness, size = brightness), alpha = .25) +
scale_color_gradient(low = "yellow", high = "red") +
geom_polygon(data = filter(australia, long < 155),
aes(x = long, y = lat, fill = subregion),
alpha = .2, color = "black") +
guides(colour = FALSE) +
guides(size = FALSE) +
guides(fill = FALSE) +
theme_void()
# co-ordinates for the arrow
arrow_data_rain <- tibble(x1 = 2011, x2 = 2010.5, y1 = 1.8, y2 = 2.65)
rain_plot <- rainfall %>%
filter(year > 1999) %>%
filter(!is.na(rainfall)) %>%
group_by(year) %>%
summarise(rainfall = mean(rainfall)) %>%
ggplot(aes(x = year, y = rainfall)) +
geom_point() +
geom_smooth(colour = "blue", se = FALSE) +
theme(axis.text.x = element_text(angle = 90)) +
labs(x = "Year", y = "Average Rainfall (mm)") +
theme_economist() +
theme(text = element_text(size = 12)) +
annotate("text", x = 2011, y = 1.35, size = 4, color = "gray20", label = "Downward trend\nin monthly rainfall\nbegan in 2010") +
geom_curve(data = arrow_data_rain, aes(x = x1, y = y1, xend = x2, yend = y2),
arrow = arrow(length = unit(0.2, "cm")), size = 0.5,
color = "gray20", curvature = 0.3)
# bring it all together
((rain_plot + fire_plot) / temperature_plot) +
plot_annotation(title = "Australian average monthly rainfall, wildfires during Dec 2019/Jan 2020, and temperature \nover time",
caption = "@ajstewart_lang")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment