`r params$set_title`

# Load libraries
library(rmarkdown)
library(knitr)
library(brclimr)
library(ggplot2)

# Echo default
opts_chunk$set(
  fig.width = 14,
  fig.height = 10,
  echo = FALSE,
  results = "asis",
  warning = TRUE
)

# Plots evaluation
temp_max_min_avg <- params$temp_max_min_avg
temp_max_min_sd <- params$temp_max_min_sd
prec_sum <- params$prec_sum
prec_avg <- params$prec_avg
prec_sd <- params$prec_sd
eto_sum <- params$eto_sum
eto_avg <- params$eto_avg
eto_sd <- params$eto_sd
rh_avg <- params$rh_avg
rh_sd <- params$rh_sd
rs_avg <- params$rs_avg
rs_sd <- params$rs_sd
knitr::asis_output("## Temperature\\n")
knitr::asis_output("### Average\\n")
tmax <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "tmax",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

tmin <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "tmin",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

tmax$name <- "Tmax_avg"
tmin$name <- "Tmin_avg"

ggplot(data = rbind(tmax, tmin), aes(x = date, y = value, color = name)) +
  geom_line() +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Temperature (average)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
tmax <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "tmax",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

tmin <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "tmin",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

tmax$name <- "Tmax_sd"
tmin$name <- "Tmin_sd"

ggplot(data = rbind(tmax, tmin), aes(x = date, y = value, color = name)) +
  geom_line() +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Temperature (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("## Precipitation\\n")
knitr::asis_output("### Sum\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "pr",
  statistics = "sum",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "blue") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Precipitation (sum)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Average\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "pr",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "blue") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Precipitation (mean)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "pr",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "blue") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Precipitation (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("## Evapotranspiration\\n")
knitr::asis_output("### Sum\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "eto",
  statistics = "sum",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "orange") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Evapotranspiration (sum)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Average\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "eto",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "orange") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Evapotranspiration (mean)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "eto",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "orange") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Evapotranspiration (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("## Relative Humidity\\n")
knitr::asis_output("### Average\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "rh",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "purple") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Relative humidity (mean)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "rh",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "purple") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Relative humidity (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("## Solar radiation\\n")
knitr::asis_output("### Average\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "rs",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "tomato3") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Solar radiation (mean)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "rh",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "tomato3") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Solar radiation (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("## Wind speed\\n")
knitr::asis_output("### Average\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "u2",
  statistics = "mean",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "darkslategrey") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Wind speed (mean)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")
knitr::asis_output("### Standart deviation\\n")
pr <- fetch_data(
  code_muni = params$code_muni,
  product = "brdwgd",
  indicator = "u2",
  statistics = "sd",
  date_start = params$date_start,
  date_end = params$date_end
)

ggplot(data = pr, aes(x = date, y = value)) +
  geom_line(color = "darkslategrey") +
  ylim(0, NA) +
  labs(
    x = "Date", 
    y = "Wind speed (sd)",
    color = ""
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "horizontal")


Try the brclimr package in your browser

Any scripts or data that you put into this service are public.

brclimr documentation built on May 29, 2024, 12:19 p.m.