Created
November 19, 2019 13:31
-
-
Save JoFAM/bccc15df4a53ead31836891bb01bcb75 to your computer and use it in GitHub Desktop.
Plotting monthly global temperatures from UAH dataset
This file contains hidden or 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
# Plot UAH monthly temperatures | |
# Joris Meys | |
# Date last modified: 2019-11-18 | |
# Create a temporary filename | |
fname <- tempfile() | |
# Download data into the temporary file | |
download.file("https://www.nsstc.uah.edu/data/msu/v6.0/tlt/uahncdc_lt_6.0.txt",destfile = fname) | |
# read in the data | |
x <- read.table(fname, header = TRUE, | |
nrows = 491) | |
# Remove temporary file | |
unlink(fname) | |
# Create a date variable representing the middle of the month | |
x$time <- as.Date(sprintf("%d-%02d-15", x$Year, x$Mo), | |
format = "%Y-%m-%d") | |
# Make month labels | |
x$month <- factor(x$Mo, | |
labels = month.abb) | |
# Create the plot | |
ggplot(tmp,aes(x=time, y=Globe)) + | |
geom_line() + | |
geom_smooth(method = "gam", | |
formula = y ~ s(x), | |
color = alpha("red",0.5)) + | |
facet_wrap( ~ month) + | |
labs( | |
title = "UAH global temp estimate by month", | |
subtitle = "Based on v.6.0 of the dataset by Christy & Spencer", | |
caption = "download data: https://www.nsstc.uah.edu/data/msu/v6.0/tlt/uahncdc_lt_6.0.txt" | |
) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment