Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# brclimr
<!-- badges: start -->
<!-- badges: end -->
R package to fetch zonal weather indicators for Brazilian municipalities.
## Installation
You can install the development version of brclimr like so:
``` r
remotes::install_gitlab(repo = "rdefreit/brclimr", host = "https://gitlab.inria.fr")
```
## Main functions
Currently, this package uses zonal weather indicators created for each Brazilian municipality with data from the BR-DWGD project (Xavier et al. 2022). For each municipality and weather indicator, a series of daily statistics was calculated considering the data cells that intersects the municipality.
For the BR-DWGD project, the following data can be retrieved with this package
```{r}
library(brclimr)
product_info(product = "brdwgd")
```
To fetch data for a specific product, indicator and statistic, use the fetch_data function. For example, lets consider the Rio de Janeiro, RJ municipality (IBGE code number 3304557), data product "brdwgd", average relative humidity, from 2010-10-15 to 2010-10-20.
```{r}
brclimr::fetch_data(
code_muni = 3304557,
product = "brdwgd",
indicator = "rh",
statistics = "mean",
date_start = as.Date("2010-10-15"),
date_end = as.Date("2010-10-20")
)
```
## Another example
```{r}
tmax <- brclimr::fetch_data(
code_muni = 3303401,
product = "brdwgd",
indicator = "tmax",
statistics = "mean",
date_start = as.Date("2010-01-01"),
date_end = as.Date("2012-01-01")
)
tmin <- brclimr::fetch_data(
code_muni = 3303401,
product = "brdwgd",
indicator = "tmin",
statistics = "mean",
date_start = as.Date("2010-01-01"),
date_end = as.Date("2012-01-01")
)
pr <- brclimr::fetch_data(
code_muni = 3303401,
product = "brdwgd",
indicator = "pr",
statistics = "sum",
date_start = as.Date("2010-01-01"),
date_end = as.Date("2012-01-01")
)
tmax$name <- "Tmax_avg"
tmin$name <- "Tmin_avg"
```
```{r}
library(ggplot2)
ggplot(data = rbind(tmax, tmin), aes(x = date, y = value, color = name)) +
geom_line() +
scale_x_date(date_breaks = "2 months", date_labels = "%m/%y") +
ylim(0, NA) +
labs(
title = "Nova Friburgo, RJ",
x = "Date",
y = "Temperature (average)",
color = ""
) +
theme_bw() +
theme(legend.position = "bottom", legend.direction = "horizontal")
```
```{r}
ggplot(data = pr, aes(x = date, y = value)) +
geom_line(color = "blue") +
scale_x_date(date_breaks = "2 months", date_labels = "%m/%y") +
ylim(0, NA) +
labs(
title = "Nova Friburgo, RJ",
x = "Date",
y = "Precipitation (sum)",
color = ""
) +
theme_bw() +
theme(legend.position = "bottom", legend.direction = "horizontal")
```