Skip to content

Instantly share code, notes, and snippets.

@conormm
Last active July 12, 2017 18:01
Show Gist options
  • Save conormm/da2bc024004157f845b40abc10f35691 to your computer and use it in GitHub Desktop.
Save conormm/da2bc024004157f845b40abc10f35691 to your computer and use it in GitHub Desktop.
library(readr)
library(dplyr)
library(ggplot2)
library(janitor)
library(broom)
library(lubridate)
# available at https://www.kaggle.com/berkeleyearth/climate-change-earth-surface-temperature-data
temp_loc <- "/Users/conormcdonald/Downloads/GlobalLandTemperatures/GlobalLandTemperaturesByCountry.csv"
temp <- read_csv(temp_loc)
temp <- temp %>%
clean_names() %>%
filter(!is.na(averagetemperature)) %>%
mutate(year = year(dt),
month = month(dt))
country_fit <- temp %>%
group_by(country) %>%
do(glance(lm(averagetemperature ~ dt, data = .)))
country_fit %>%
ungroup() %>%
filter(r.squared > 0.10) %>%
mutate(country = reorder(country, r.squared)) %>%
ggplot(aes(country, r.squared, colour = r.squared)) +
geom_point(alpha = 0.8) +
coord_flip() +
guides(colour = FALSE) +
labs(title = "R-Sqaured of average land temperature explained by time",
subtitle = "Showing countries with R-Sq > 0.10",
y = "R-Sqaured",
x = "Country")
temp %>%
filter(country == "Indonesia") %>%
group_by(year) %>%
summarise(ave_temp = mean(averagetemperature)) %>%
ggplot(aes(year, ave_temp)) +
geom_point(alpha = 0.6) +
geom_smooth(method = "lm") +
labs(title = "Average land temperature by year for Indonesia")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment