library(RODBC)
library(ggplot2)
library(mgcv)
## Loading required package: nlme
## This is mgcv 1.7-27. For overview type 'help("mgcv-package")'.
con <- odbcConnect("clima")
##
query <- "select * from chirps.by_mun"
d <- sqlQuery(con, query)
library(ggplot2)
aa <- split(d, d$nom_mun)
f <- function(d) {
d <- subset(d, d$yr < 2014)
g0 <- ggplot(d, aes(x = fdate, y = prec))
g1 <- g0 + geom_line() + facet_wrap(~nom_mun) + geom_smooth(method = "loess")
print(g1)
g0 <- ggplot(d, aes(x = mn, y = prec))
g1 <- g0 + geom_line() + facet_wrap(~yr)
print(g1)
g0 <- ggplot(d, aes(x = mn, y = prec, color = as.factor(yr)))
g1 <- g0 + geom_line()
print(g1)
prec <- ts(d$prec, start = c(1981, 1), frequency = 12)
a <- stl(prec, s.window = 12)
plot(a)
}
lapply(aa[1:20], f)
## $Abalá
## NULL
##
## $Acacoyagua
## NULL
##
## $Acala
## NULL
##
## $Acanceh
## NULL
##
## $Acapetahua
## NULL
##
## $Akil
## NULL
##
## $Altamirano
## NULL
##
## $Amatán
## NULL
##
## $`Amatenango de la Frontera`
## NULL
##
## $`Amatenango del Valle`
## NULL
##
## $`Angel Albino Corzo`
## NULL
##
## $Baca
## NULL
##
## $Balancán
## NULL
##
## $`Bejucal de Ocampo`
## NULL
##
## $`Bella Vista`
## NULL
##
## $`Benemérito de las Américas`
## NULL
##
## $`Benito Juárez`
## NULL
##
## $Bochil
## NULL
##
## $Bokobá
## NULL
##
## $Buctzotz
## NULL