y. zhang
03-28-2017
The annual precipitation data for Texas is available from the Texas Water Development Board.
The data file url is http://midgewater.twdb.texas.gov/evaporation/quadrangle/XXX/precipitation-tabular.txt, where XXX is the quadrangle number, therefore we can loop all possible numbers to download all data files.
quadrangleno=c(104:108,204:208,304:309,404:414,
504:514,601:614,701:714,803:814,907:912,1008:1011,1108:1110,1210)
url1 <- "http://midgewater.twdb.texas.gov/evaporation/quadrangle/"
url2 <- "/precipitation-tabular.txt"
url <- paste(url1,quadrangleno,url2,sep="")
destfile <-paste("./tx_precipitation_data/",quadrangleno,"_data.txt",sep="")
for (i in 1:length(url))
download.file(url[i],destfile=destfile[i])
library(ggplot2)
library(reshape2)
library(dplyr)
datafile <- "./tx_precipitation_data/texas_prcipitation_1940-2015.txt"
pd <- read.table(datafile,header=T,comment.char="",check.names=F)
names(pd)[1] <- "QUAD"
pd_all <- aggregate(pd$ANNUAL,by=list(YEAR=pd$YEAR),mean)
colnames(pd_all)[2] <- "ANNUAL"
pd_all <- mutate(pd_all,QUAD=9999L)
pd_all <- merge(pd,pd_all,all=T)
region <- data.frame(name=c("Austin","Houston","San Antonio","Dallas","TX"),
quad=c(710,812,809,511,9999))
sq <- c(710,812,9999)
pd1 <- subset(pd_all[,c("QUAD","YEAR","ANNUAL"),drop=F], QUAD %in% sq)
pd2 <- mutate(pd1,location=region$name[match(pd1$QUAD, region$quad)])
pd_long <- melt(pd2, id=c("YEAR","QUAD","location") )
g <- ggplot(pd_long,aes(y=value,x=YEAR,colour=location))+geom_line()
g <- g+xlab("Years")+ylab("Annual Precipitation (unit: inch)")
g <- g+theme(axis.text=element_text(size=12), axis.title=element_text(size=14),
legend.title=element_text(size=14), legend.text=element_text(size=12))
g <- g+xlim(1945,2015)
g <- g+geom_smooth(se=F)