scripts_1/step_1-code-descriptive.R

rm(list=ls())

# Packages -------
pack <- c("tidyverse","extraDistr","devtools","Formula","tictoc","betareg","cowplot")

package.check <- lapply(
  pack,
  FUN = function(x) {
    if (!require(x, character.only = TRUE)) {
      install.packages(x, dependencies = TRUE)
      library(x, character.only = TRUE)
    }
  }
)

devtools::load_all() # loading my functions

# Database------

## Loading database------

data("data_1")

## Parse database------
mes = factor(month.abb,levels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))
database = data_1 %>% filter(Estação=="1") %>%
  mutate(Mês = rep(mes,21) %>% rep(14),
         data=paste0(Ano,"/",Mês),
         Group = rep(c("Group A","Group B","Group A"),c(5,6,1)) %>% rep(21) %>% rep(14),
         t =seq(1,252) %>% rep(14),
         tt = seq(1,12) %>% rep(21) %>% rep(14),
         Grupos = rep(paste0("Grupo ",c(1,2,3,3,2,1,1,3,2,3,3,3,1,1)),each=252),
         Altitude_fac = as.factor(Altitude),
         lat = scale(LATITUDE%>%as.numeric()),
         long = scale(LONGITUDE%>%as.numeric()))

database <- database %>% mutate(cost = cos(2*pi*tt/12),sent=sin(2*pi*tt/12),
                                Ano_n=as.numeric(Ano))


head(database)


q_est <- database %>% group_by(t) %>% summarise(m = sd(UR))
plot.ts(q_est$m)

TT=144
database <-database %>% group_by(Estações) %>% slice(1:TT) %>% data.frame()
fig1 = database %>%dplyr::group_split(Grupos) %>%
  purrr::map(
    ~ggplot(.) + geom_line(aes(t,UR))+geom_point(aes(t,UR))+
      #ylab("Relative humidity")+ scale_y_continuous(labels=scales::percent)+
      #scale_x_discrete(labels = c(month.abb))+
      facet_grid(~Estações)+
      theme_bw()+
      theme(axis.text.x=element_text(angle=90,size=8)))%>%
  cowplot::plot_grid(plotlist = .,nrow=3)
x11()
fig1




fig1 = database %>%dplyr::group_split(Grupos) %>%
  purrr::map(
    ~ggplot(.) + geom_histogram(aes(UR))+
      #ylab("Relative humidity")+ scale_y_continuous(labels=scales::percent)+
      #scale_x_discrete(labels = c(month.abb))+
      facet_grid(~Estações)+
      theme_bw()+
      theme(axis.text.x=element_text(angle=90,size=8)))%>%
  cowplot::plot_grid(plotlist = .,nrow=3)
x11()
fig1







fig1 = database %>%dplyr::group_split(Grupos) %>%
  purrr::map(
    ~ggplot(.) + geom_boxplot(aes(Mês,UR))+
      ylab("Relative humidity")+ scale_y_continuous(labels=scales::percent)+
      scale_x_discrete(labels = c(month.abb))+
      facet_grid(~Esta??es)+
      theme_bw()+
      theme(axis.text.x=element_text(angle=90,size=8)))%>%
  cowplot::plot_grid(plotlist = .,nrow=3)
x11()
fig1



fig1 = ggplot(database) + geom_boxplot(aes(M?s,UR))+
      ylab("Relative humidity")+ scale_y_continuous(labels=scales::percent)+
      scale_x_discrete(labels = c(month.abb))+
      theme_bw()+
      theme(axis.text.x=element_text(angle=90,size=8))
x11()
fig1


database %>% group_by(M?s) %>% summarise(s=sd(UR))


fig1 = ggplot(database) + geom_point(aes(t,UR))+geom_line(aes(t,UR))+
  ylab("Relative humidity")+ scale_y_continuous(labels=scales::percent)+
  theme_bw()+
  theme(axis.text.x=element_text(angle=90,size=8))
x11()
fig1
leonardobfn/ThesiR documentation built on March 19, 2022, 5:42 a.m.