library(plyr)
library(ggplot2)
library(quantreg)
## Loading required package: SparseM
##
## Attaching package: 'SparseM'
##
## The following object is masked from 'package:base':
##
## backsolve
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.2.3
##
## Attaching package: 'lubridate'
##
## The following object is masked from 'package:plyr':
##
## here
L = "http://models.weatherbell.com/news/tuscon_pwat_1958_2014.dat"
L = "http://models.weatherbell.com/news/conus_pwat_1958_2014.dat"
df = read.table(L, sep=',', stringsAsFactors = FALSE)
names(df) = c("TD", "PW")
x = character()
class(x) = "Date"
for(i in 1:nrow(df)) x[i] = as.Date(unlist(strsplit(df$TD[i], "Z"))[2], "%d%B%Y")
df$Date = x
df$Month = as.integer(month(df$Date))
df$Year = as.integer(year(df$Date))
MY = ddply(df, .(Month, Year), summarize,
AvgPW = mean(PW))
MY$MoA = factor(month.abb[MY$Month], levels = month.abb[1:12])
MY$PW = MY$AvgPW * 2.54
write.table(MY, file = "PW.txt", row.names = FALSE)
ggplot(MY, aes(x = Year, y = AvgPW * 2.54)) +
geom_line() +
geom_smooth(method = lm) +
facet_wrap(~ MoA, nrow = 1) +
ylab("CONUS Avg Precipitable Water (cm) by Month") +
theme_bw()
