Os objetivos deste post são:
Apresentar um script inicial para extrair vetor com série de vazões diárias do banco de dados Hidroweb;
Organizar os dados em um data frame com duas colunas [data, Vazões];
Gerar um gráfico com a série de vazões diárias;
Organizar os dados para um formato de série mensal e gerar um gráfico; e
Organizar os dados para um formato de série anual e gerar um gráfico.
#Dados: código da estação,data inicial,data final,tipo de dados,consistência
# Define url with the following information
# (1) código da estação
# (2) data inicial (dd/mm/yyyy)
# (3) data final (dd/mm/yyyy)
# (4) tipo de dado: 3 para vazão
# (5) Consistência: 1 não consistido or 2 consistido
gauge.number<-14100000
initial.date<-"01/01/2010"
final.date<-"01/01/2016"
type.of.data<-3
quality.control<-2
# Carrega pacote XML
library(XML)
#Link automático para acessar o banco de dados conforme dados digitados para estação no passo anterior
link<-cbind("http://telemetriaws1.ana.gov.br/ServiceANA.asmx/HidroSerieHistorica?codEstacao=",gauge.number,"&dataInicio=",initial.date,"&dataFim=",final.date,"&tipoDados=",type.of.data,"&nivelConsistencia=",quality.control)
link<-paste(link, collapse = "")
#Converte os dados do link para xml
xml.data <- xmlParse(link)
# Transforma os dados xml em formato data frame
retrieved.data <- xmlToDataFrame(nodes = getNodeSet(xml.data,"//DocumentElement/SerieHistorica"))
#Amostra da estrutura dos dados baixados
str(retrieved.data)
## 'data.frame': 73 obs. of 78 variables:
## $ EstacaoCodigo : chr "14100000" "14100000" "14100000" "14100000" ...
## $ NivelConsistencia : chr "1" "1" "1" "1" ...
## $ DataHora : chr "2016-01-01 00:00:00" "2015-12-01 00:00:00" "2015-11-01 00:00:00" "2015-10-01 00:00:00" ...
## $ MediaDiaria : chr "1" "1" "1" "1" ...
## $ MetodoObtencaoVazoes: chr "1" "1" "1" "1" ...
## $ Maxima : chr "79141.8" "64259.6" "58396.6" "95271.5" ...
## $ Minima : chr "64633.9" "58885.7" "54573.4" "52416.1" ...
## $ Media : chr "73523.7" "61634.2" "56570.2" "66410.8" ...
## $ DiaMaxima : chr "30" "31" "30" "1" ...
## $ DiaMinima : chr "1" "1" "1" "27" ...
## $ MaximaStatus : chr "1" "1" "1" "2" ...
## $ MinimaStatus : chr "1" "1" "1" "2" ...
## $ MediaStatus : chr "1" "1" "1" "2" ...
## $ MediaAnual : chr "" "" "" "" ...
## $ MediaAnualStatus : chr "0" "0" "0" "0" ...
## $ Vazao01 : chr "64633.9" "58885.7" "54573.4" "95271.5" ...
## $ Vazao02 : chr "65125.4" "59322.6" "55199.6" "92803" ...
## $ Vazao03 : chr "65706.6" "59651.5" "55751.1" "90835.3" ...
## $ Vazao04 : chr "66320.2" "60009.1" "56147.1" "88158.9" ...
## $ Vazao05 : chr "66996.3" "60395.7" "56598" "86011.7" ...
## $ Vazao06 : chr "67765.6" "60728.3" "56971" "83491.3" ...
## $ Vazao07 : chr "68420.8" "60978.5" "57425.9" "80818.1" ...
## $ Vazao08 : chr "69019.8" "61173.5" "57721.4" "78457.7" ...
## $ Vazao09 : chr "69501.3" "61368.9" "57748.4" "76044.5" ...
## $ Vazao10 : chr "70075.7" "61452.8" "57748.4" "73489.9" ...
## $ Vazao11 : chr "71110.9" "61424.8" "57640.8" "71263.9" ...
## $ Vazao12 : chr "72001.3" "61368.9" "57479.6" "69109.9" ...
## $ Vazao13 : chr "72681.2" "61313" "57318.7" "67114.3" ...
## $ Vazao14 : chr "73302.8" "61313" "57024.4" "65038.5" ...
## $ Vazao15 : chr "73990.3" "61229.3" "56704.4" "63059.4" ...
## $ Vazao16 : chr "74555.7" "61173.5" "56438.6" "61368.9" ...
## $ Vazao17 : chr "75092.1" "61313" "56147.1" "59899" ...
## $ Vazao18 : chr "75630.9" "61424.8" "55856.5" "58017.9" ...
## $ Vazao19 : chr "76172" "61536.7" "55645.8" "56971" ...
## $ Vazao20 : chr "76747.6" "61704.8" "55461.8" "55672.1" ...
## $ Vazao21 : chr "77261.4" "61845" "55435.5" "54781.6" ...
## $ Vazao22 : chr "77615.9" "62041.7" "55409.3" "53951.6" ...
## $ Vazao23 : chr "78068.5" "62295.2" "55566.9" "53359.8" ...
## $ Vazao24 : chr "78425.3" "62408.1" "55724.8" "52848.4" ...
## $ Vazao25 : chr "78652.8" "62747.4" "56147.1" "52543" ...
## $ Vazao26 : chr "78880.7" "62945.9" "56544.8" "52492.2" ...
## $ Vazao27 : chr "79011.2" "63173.2" "56944.3" "52416.1" ...
## $ Vazao28 : chr "79109.1" "63458" "57452.7" "52670.1" ...
## $ Vazao29 : chr "79109.1" "63743.6" "57883" "53103.7" ...
## $ Vazao30 : chr "79141.8" "63972.6" "58396.6" "53565.1" ...
## $ Vazao31 : chr "79109.1" "64259.6" "" "54106.6" ...
## $ Vazao01Status : chr "1" "1" "1" "1" ...
## $ Vazao02Status : chr "1" "1" "1" "1" ...
## $ Vazao03Status : chr "1" "1" "1" "1" ...
## $ Vazao04Status : chr "1" "1" "1" "1" ...
## $ Vazao05Status : chr "1" "1" "1" "1" ...
## $ Vazao06Status : chr "1" "1" "1" "1" ...
## $ Vazao07Status : chr "1" "1" "1" "1" ...
## $ Vazao08Status : chr "1" "1" "1" "1" ...
## $ Vazao09Status : chr "1" "1" "1" "1" ...
## $ Vazao10Status : chr "1" "1" "1" "1" ...
## $ Vazao11Status : chr "1" "1" "1" "1" ...
## $ Vazao12Status : chr "1" "1" "1" "2" ...
## $ Vazao13Status : chr "1" "1" "1" "1" ...
## $ Vazao14Status : chr "1" "1" "1" "1" ...
## $ Vazao15Status : chr "1" "1" "1" "1" ...
## $ Vazao16Status : chr "1" "1" "1" "1" ...
## $ Vazao17Status : chr "1" "1" "1" "1" ...
## $ Vazao18Status : chr "1" "1" "1" "1" ...
## $ Vazao19Status : chr "1" "1" "1" "2" ...
## $ Vazao20Status : chr "1" "1" "1" "1" ...
## $ Vazao21Status : chr "1" "1" "1" "1" ...
## $ Vazao22Status : chr "1" "1" "1" "1" ...
## $ Vazao23Status : chr "1" "1" "1" "1" ...
## $ Vazao24Status : chr "1" "1" "1" "1" ...
## $ Vazao25Status : chr "1" "1" "1" "2" ...
## $ Vazao26Status : chr "1" "1" "1" "1" ...
## $ Vazao27Status : chr "1" "1" "1" "1" ...
## $ Vazao28Status : chr "1" "1" "1" "1" ...
## $ Vazao29Status : chr "1" "1" "1" "1" ...
## $ Vazao30Status : chr "1" "1" "1" "1" ...
## $ Vazao31Status : chr "1" "1" "0" "1" ...
## $ DataIns : chr "2017-12-22 00:00:00" "2017-12-22 00:00:00" "2017-12-22 00:00:00" "2017-12-22 00:00:00" ...
#Instala pacote para manipular séries temporais
#devtools::install_github("tidyverse/lubridate")
library("lubridate")
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#Extrai as datas contidas na coluna 3
dates<-retrieved.data [,3]
#Inicializa vetores que armazenaram a data inicial e final para cada mês do histórico
initial.day<-"2000-01-01"
initial.day<-as.Date(initial.day,"%Y-%m-%d")
final.day<-"2000-01-01"
final.day<-as.Date(final.day,"%Y-%m-%d")
# Retira a data de início e fim de cada mês
for(i in 1:length(dates)){
temp<-0
temp<-strsplit(dates[i], " ")
temp<-temp[[1]]
initial.day[i]<-temp[1]
temp<-ymd(initial.day[i])+days(days_in_month((initial.day[i])))-1
final.day[i]<-temp
}
#Vetores com a data de início e fim para cada mês
initial.day
## [1] "2016-01-01" "2015-12-01" "2015-11-01" "2015-10-01" "2015-09-01"
## [6] "2015-08-01" "2015-07-01" "2015-06-01" "2015-05-01" "2015-04-01"
## [11] "2015-03-01" "2015-02-01" "2015-01-01" "2014-12-01" "2014-11-01"
## [16] "2014-10-01" "2014-09-01" "2014-08-01" "2014-07-01" "2014-06-01"
## [21] "2014-05-01" "2014-04-01" "2014-03-01" "2014-02-01" "2014-01-01"
## [26] "2013-12-01" "2013-11-01" "2013-10-01" "2013-09-01" "2013-08-01"
## [31] "2013-07-01" "2013-06-01" "2013-05-01" "2013-04-01" "2013-03-01"
## [36] "2013-02-01" "2013-01-01" "2012-12-01" "2012-11-01" "2012-10-01"
## [41] "2012-09-01" "2012-08-01" "2012-07-01" "2012-06-01" "2012-05-01"
## [46] "2012-04-01" "2012-03-01" "2012-02-01" "2012-01-01" "2011-12-01"
## [51] "2011-11-01" "2011-10-01" "2011-09-01" "2011-08-01" "2011-07-01"
## [56] "2011-06-01" "2011-05-01" "2011-04-01" "2011-03-01" "2011-02-01"
## [61] "2011-01-01" "2010-12-01" "2010-11-01" "2010-10-01" "2010-09-01"
## [66] "2010-08-01" "2010-07-01" "2010-06-01" "2010-05-01" "2010-04-01"
## [71] "2010-03-01" "2010-02-01" "2010-01-01"
final.day
## [1] "2016-01-31" "2015-12-31" "2015-11-30" "2015-10-31" "2015-09-30"
## [6] "2015-08-31" "2015-07-31" "2015-06-30" "2015-05-31" "2015-04-30"
## [11] "2015-03-31" "2015-02-28" "2015-01-31" "2014-12-31" "2014-11-30"
## [16] "2014-10-31" "2014-09-30" "2014-08-31" "2014-07-31" "2014-06-30"
## [21] "2014-05-31" "2014-04-30" "2014-03-31" "2014-02-28" "2014-01-31"
## [26] "2013-12-31" "2013-11-30" "2013-10-31" "2013-09-30" "2013-08-31"
## [31] "2013-07-31" "2013-06-30" "2013-05-31" "2013-04-30" "2013-03-31"
## [36] "2013-02-28" "2013-01-31" "2012-12-31" "2012-11-30" "2012-10-31"
## [41] "2012-09-30" "2012-08-31" "2012-07-31" "2012-06-30" "2012-05-31"
## [46] "2012-04-30" "2012-03-31" "2012-02-29" "2012-01-31" "2011-12-31"
## [51] "2011-11-30" "2011-10-31" "2011-09-30" "2011-08-31" "2011-07-31"
## [56] "2011-06-30" "2011-05-31" "2011-04-30" "2011-03-31" "2011-02-28"
## [61] "2011-01-31" "2010-12-31" "2010-11-30" "2010-10-31" "2010-09-30"
## [66] "2010-08-31" "2010-07-31" "2010-06-30" "2010-05-31" "2010-04-30"
## [71] "2010-03-31" "2010-02-28" "2010-01-31"
#Extrai matriz com dados de vazões diárias da variável retrieved.data
qobs.data.frame<-retrieved.data[,16:46]
qobs.data.frame[qobs.data.frame==""]<-NA
#Instala e carrega pacotes auxiliares para manipular séries temporais
install.packages("lubridate")
## Warning: package 'lubridate' is in use and will not be installed
install.packages("dplyr")
## Warning: package 'dplyr' is in use and will not be installed
library("lubridate")
library("dplyr")
#cria e inicializa variável para armazenar os dados diários de vazão
qobs<-0
#cria e inicializ avariável para armazenar as datas
period<-as.Date("1900-01-01")
#loop para organizar os dados diários e as respectivas datas em ordem crescente
for(i in 1:nrow(qobs.data.frame)){
j=nrow(qobs.data.frame)-i+1
temp.days<-days_in_month((initial.day[j]))
temp.qobs<-qobs.data.frame[j,1:as.integer(temp.days)]
qobs<-c(qobs,as.numeric(temp.qobs))
period<-c(period,seq(from=initial.day[j],to=final.day[j],by=1))
temp.qobs<-0
}
#remove o primeiro elemento dos vetores gerados no momento que as variáveis foram criadas
qobs<-qobs[-1]
period<-period[-1]
#cria data frame com duas colunas [datas,Vazões]
qobs.ts.day<-data_frame(period)
## Warning: `data_frame()` is deprecated as of tibble 1.1.0.
## Please use `tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
qobs.ts.day<-cbind(qobs.ts.day,qobs)
colnames(qobs.ts.day)<-cbind("date","discharge")
#mostra primeiras linhas do data frame
head(qobs.ts.day)
## date discharge
## 1 2010-01-01 75797.9
## 2 2010-01-02 76447.9
## 3 2010-01-03 77100.0
## 4 2010-01-04 77754.2
## 5 2010-01-05 78410.6
## 6 2010-01-06 79135.0
#cria um data frame agrupando o histórico de vazões diárias em passos de tempo mensal
#os valores de vazões consistem na média mensal
qobs.ts.month<-qobs.ts.day %>% group_by(month=floor_date(date, "month"))%>%summarize(discharge=mean(discharge))
## `summarise()` ungrouping output (override with `.groups` argument)
#mostra as primeiras linhas do data frame criado
qobs.ts.month
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 73 x 2
## month discharge
## <date> <dbl>
## 1 2010-01-01 83409.
## 2 2010-02-01 91906.
## 3 2010-03-01 99379.
## 4 2010-04-01 112245.
## 5 2010-05-01 130197.
## 6 2010-06-01 135271.
## 7 2010-07-01 126783.
## 8 2010-08-01 100403.
## 9 2010-09-01 58132.
## 10 2010-10-01 35732.
## # ... with 63 more rows
#cria um data frame agrupando o histórico de vazões diárias em passos de tempo anual
#os valores de vazões consistem nas médias anuais
qobs.ts.year<-qobs.ts.day %>% group_by(year=floor_date(date, "year"))%>%summarize(discharge=mean(discharge))
## `summarise()` ungrouping output (override with `.groups` argument)
#mostra as primeiras linhas do data frame criado
qobs.ts.year
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 7 x 2
## year discharge
## <date> <dbl>
## 1 2010-01-01 89400.
## 2 2011-01-01 94840.
## 3 2012-01-01 108377.
## 4 2013-01-01 112083.
## 5 2014-01-01 115927.
## 6 2015-01-01 112506.
## 7 2016-01-01 73524.
#Carrega pacotes gráficos
library("ggplot2")
#install.packages("hrbrthemes")
#devtools::install_github("hrbrmstr/hrbrthemes")
library("hrbrthemes")
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
# Gera gráfico com série diária
p.day <- ggplot(qobs.ts.day, aes(x=date, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
scale_x_date(date_labels = "%m-%Y",date_breaks="6 month")+
geom_line( color="red",size=1.2) +
ggtitle("Série Diária de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.day
#Gera Gráfico com série mensal
p.month <- ggplot(qobs.ts.month, aes(x=month, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
scale_x_date(date_labels = "%m-%Y",date_breaks="3 month")+
geom_line( color="red",size=1.2) +
ggtitle("Série Mensal de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.month
#Gera gráfico com série anual
p.anual <- ggplot(qobs.ts.year, aes(x=year, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
#scale_x_date(date_labels = "%Y",date_breaks="1 year")+
geom_line( color="red",size=1.2) +
ggtitle("Série Anual de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.anual
#Dados: código da estação,data inicial,data final,tipo de dados,consistência
# Define url with the following information
# (1) código da estação
# (2) data inicial (dd/mm/yyyy)
# (3) data final (dd/mm/yyyy)
# (4) tipo de dado: 3 para vazão
# (5) Consistência: 1 não consistido or 2 consistido
gauge.number<-14100000
initial.date<-"01/01/2010"
final.date<-"01/01/2016"
type.of.data<-3
quality.control<-2
# Carrega pacote XML
library(XML)
#Link automático para acessar o banco de dados conforme dados digitados para estação no passo anterior
link<-cbind("http://telemetriaws1.ana.gov.br/ServiceANA.asmx/HidroSerieHistorica?codEstacao=",gauge.number,"&dataInicio=",initial.date,"&dataFim=",final.date,"&tipoDados=",type.of.data,"&nivelConsistencia=",quality.control)
link<-paste(link, collapse = "")
#Converte os dados do link para xml
xml.data <- xmlParse(link)
# Transforma os dados xml em formato data frame
retrieved.data <- xmlToDataFrame(nodes = getNodeSet(xml.data,"//DocumentElement/SerieHistorica"))
#Instala pacote para manipular séries temporais
#devtools::install_github("tidyverse/lubridate")
library("lubridate")
library("dplyr")
#Extrai as datas contidas na coluna 3
dates<-retrieved.data [,3]
#Inicializa vetores que armazenaram a data inicial e final para cada mês do histórico
initial.day<-"2000-01-01"
initial.day<-as.Date(initial.day,"%Y-%m-%d")
final.day<-"2000-01-01"
final.day<-as.Date(final.day,"%Y-%m-%d")
# Retira a data de início e fim de cada mês
for(i in 1:length(dates)){
temp<-0
temp<-strsplit(dates[i], " ")
temp<-temp[[1]]
initial.day[i]<-temp[1]
temp<-ymd(initial.day[i])+days(days_in_month((initial.day[i])))-1
final.day[i]<-temp
}
#Extrai matriz com dados de vazões diárias da variável retrieved.data
qobs.data.frame<-retrieved.data[,16:46]
qobs.data.frame[qobs.data.frame==""]<-NA
#Instala e carrega pacotes auxiliares para manipular séries temporais
install.packages("lubridate")
## Warning: package 'lubridate' is in use and will not be installed
install.packages("dplyr")
## Warning: package 'dplyr' is in use and will not be installed
library("lubridate")
library("dplyr")
#cria e inicializa variável para armazenar os dados diários de vazão
qobs<-0
#cria e inicializ avariável para armazenar as datas
period<-as.Date("1900-01-01")
#loop para organizar os dados diários e as respectivas datas em ordem crescente
for(i in 1:nrow(qobs.data.frame)){
j=nrow(qobs.data.frame)-i+1
temp.days<-days_in_month((initial.day[j]))
temp.qobs<-qobs.data.frame[j,1:as.integer(temp.days)]
qobs<-c(qobs,as.numeric(temp.qobs))
period<-c(period,seq(from=initial.day[j],to=final.day[j],by=1))
temp.qobs<-0
}
#remove o primeiro elemento dos vetores gerados no momento que as variáveis foram criadas
qobs<-qobs[-1]
period<-period[-1]
#cria data frame com duas colunas [datas,Vazões]
qobs.ts.day<-data_frame(period)
qobs.ts.day<-cbind(qobs.ts.day,qobs)
colnames(qobs.ts.day)<-cbind("date","discharge")
#cria um data frame agrupando o histórico de vazões diárias em passos de tempo mensal
#os valores de vazões consistem na média mensal
qobs.ts.month<-qobs.ts.day %>% group_by(month=floor_date(date, "month"))%>%summarize(discharge=mean(discharge))
## `summarise()` ungrouping output (override with `.groups` argument)
#mostra as primeiras linhas do data frame criado
qobs.ts.month
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 73 x 2
## month discharge
## <date> <dbl>
## 1 2010-01-01 83409.
## 2 2010-02-01 91906.
## 3 2010-03-01 99379.
## 4 2010-04-01 112245.
## 5 2010-05-01 130197.
## 6 2010-06-01 135271.
## 7 2010-07-01 126783.
## 8 2010-08-01 100403.
## 9 2010-09-01 58132.
## 10 2010-10-01 35732.
## # ... with 63 more rows
#cria um data frame agrupando o histórico de vazões diárias em passos de tempo anual
#os valores de vazões consistem nas médias anuais
qobs.ts.year<-qobs.ts.day %>% group_by(year=floor_date(date, "year"))%>%summarize(discharge=mean(discharge))
## `summarise()` ungrouping output (override with `.groups` argument)
#mostra as primeiras linhas do data frame criado
qobs.ts.year
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 7 x 2
## year discharge
## <date> <dbl>
## 1 2010-01-01 89400.
## 2 2011-01-01 94840.
## 3 2012-01-01 108377.
## 4 2013-01-01 112083.
## 5 2014-01-01 115927.
## 6 2015-01-01 112506.
## 7 2016-01-01 73524.
#Carrega pacotes gráficos
library("ggplot2")
#install.packages("hrbrthemes")
#devtools::install_github("hrbrmstr/hrbrthemes")
library("hrbrthemes")
# Gera gráfico com série diária
p.day <- ggplot(qobs.ts.day, aes(x=date, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
scale_x_date(date_labels = "%m-%Y",date_breaks="6 month")+
geom_line( color="red",size=1.2) +
ggtitle("Série Diária de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.day
#Gera Gráfico com série mensal
p.month <- ggplot(qobs.ts.month, aes(x=month, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
scale_x_date(date_labels = "%m-%Y",date_breaks="3 month")+
geom_line( color="red",size=1.2) +
ggtitle("Série Mensal de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.month
#Gera gráfico com série anual
p.anual <- ggplot(qobs.ts.year, aes(x=year, y=discharge)) +
xlab("Data")+
ylab("Vazões (m³/s)")+
#scale_x_date(date_labels = "%Y",date_breaks="1 year")+
geom_line( color="red",size=1.2) +
ggtitle("Série Anual de Vazões")+
theme(
plot.title = element_text(color = "black", size = 16, face = "bold",hjust=0.5),
panel.background = element_rect(fill = "gray93",
colour = "gray93",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white"),axis.text.x=element_text(angle=60, hjust=1),
axis.text = element_text(size = rel(1.2), colour = "black"),
axis.title.y = element_text(size = rel(1.6), angle = 90,face = "bold"),
axis.title.x = element_text(size = rel(1.6), angle = 0,face = "bold")
)
p.anual