Skip to content

Commit

Permalink
visualizacoes no readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrecenti committed Aug 29, 2022
1 parent 3dc4ffa commit 892987d
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 22 deletions.
140 changes: 119 additions & 21 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,150 @@ output: github_document

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
```{r, include = FALSE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
out.width = "100%",
dpi = 300
)
library(tidyverse)
```

# ibdp

<!-- badges: start -->
<!-- badges: end -->

The goal of ibdp is to ...
Materiais da apresentação no Congresso do IBDP.

```{r}
# base será colocada nos releases.
pgfn <- readr::read_rds("data-raw/pgfn.rds")
```

## Installation
## Visualizações

You can install the development version of ibdp from [GitHub](https://github.com/) with:
### Tabela

``` r
# install.packages("devtools")
devtools::install_github("abjur/ibdp")
Tipo de crédito

```{r}
# tabela
pgfn |>
count(tipo_credito, sort = TRUE) |>
mutate(prop = scales::percent(n / sum(n))) |>
knitr::kable()
```

## Example
Situação da inscrição

This is a basic example which shows you how to solve a common problem:
```{r}
pgfn |>
count(tipo_situacao_inscricao, sort = TRUE) |>
mutate(prop = scales::percent(n / sum(n))) |>
knitr::kable()
```


### Mapa

```{r}
# mapa
estados <- geobr::read_state(showProgress = FALSE)
codigos <- estados |>
as_tibble() |>
select(code_state, abbrev_state)
populacao <- abjData::pnud_uf |>
filter(ano == 2010) |>
select(code_state = uf, popt) |>
left_join(codigos, "code_state")
pgfn_uf <- pgfn |>
group_by(abbrev_state = uf_unidade_responsavel) |>
summarise(
n = n(),
valor = sum(valor_consolidado)
) |>
left_join(populacao, "abbrev_state") |>
mutate(
n_pop = n / popt,
vl_pop = valor / popt
)
estados |>
left_join(pgfn_uf, c("abbrev_state")) |>
ggplot() +
geom_sf(aes(fill = vl_pop), color = "black", size = .1) +
scale_fill_viridis_c(
begin = .2, end = .8,
option = "A", trans = "log10"
) +
theme_void() +
labs(
title = "Dívida total / população"
)
```{r example}
library(ibdp)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
### No tempo

```{r}
pgfn_mes <- pgfn |>
mutate(data = lubridate::floor_date(data_inscricao, "month")) |>
filter(data >= "2008-01-01") |>
count(data)
pgfn_mes |>
ggplot(aes(x = data, y = n/1e3)) +
geom_line(size = 1) +
theme_minimal() +
scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
labs(
x = "Mês", y = "Quantidade (milhares)",
title = "Quantidade de inscrições ao longo dos anos"
)
```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:
## Modelo

```{r}
library(tsibble)
library(fable)
pgfn_tsibble <- pgfn_mes |>
mutate(data = yearmonth(data), n = sqrt(n/1e3)) |>
as_tsibble(index = data)
fit <- pgfn_tsibble |>
model(
model = ARIMA(n ~ pdq(2,1,2) + PDQ(1,1,1))
)
fit |>
forecast(h = 12) |>
mutate(.mean = (.mean^2), n = (n^2)) |>
autoplot(pgfn_tsibble |> mutate(n = (n^2))) +
theme_minimal() +
labs(
x = "Mês",
y = "Quantidade (milhares)",
title = "Quantidade de inscrições ao longo dos anos"
)
```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.

## Apresentação

Link da apresentação [aqui](https://docs.google.com/presentation/d/1sFtU7FqHGEV7OOjBLaGT7dh5WQNL3EhuMOAf_p6y3zY/edit?usp=sharing).
166 changes: 166 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# ibdp

<!-- badges: start -->
<!-- badges: end -->

Materiais da apresentação no Congresso do IBDP.

``` r
# base será colocada nos releases.
pgfn <- readr::read_rds("data-raw/pgfn.rds")
```

## Visualizações

### Tabela

Tipo de crédito

``` r
# tabela
pgfn |>
count(tipo_credito, sort = TRUE) |>
mutate(prop = scales::percent(n / sum(n))) |>
knitr::kable()
```

| tipo_credito | n | prop |
|:---------------------------------------|--------:|:---------|
| OUTROS | 5838365 | 98.3284% |
| CONTRIBUICAO NAO REPASSADA | 59766 | 1.0066% |
| AFERICAO INDIRETA | 32093 | 0.5405% |
| Não Informado | 3290 | 0.0554% |
| SOLIDARIEDADE | 1952 | 0.0329% |
| ARREMATACAO | 1138 | 0.0192% |
| SUCUMBENCIA | 583 | 0.0098% |
| RECLAMATORIA TRABALHISTA JUST TRABALHO | 416 | 0.0070% |
| NATUREZA NAO PREVIDENCIARIA | 15 | 0.0003% |

Situação da inscrição

``` r
pgfn |>
count(tipo_situacao_inscricao, sort = TRUE) |>
mutate(prop = scales::percent(n / sum(n))) |>
knitr::kable()
```

| tipo_situacao_inscricao | n | prop |
|:------------------------------|--------:|:--------|
| Em cobrança | 4756355 | 80.105% |
| Benefício Fiscal | 1165621 | 19.631% |
| Garantia | 9556 | 0.161% |
| Suspenso por decisão judicial | 5093 | 0.086% |
| Em negociação | 993 | 0.017% |

### Mapa

``` r
# mapa
estados <- geobr::read_state(showProgress = FALSE)
#> Loading required namespace: sf
#> Using year 2010

codigos <- estados |>
as_tibble() |>
select(code_state, abbrev_state)

populacao <- abjData::pnud_uf |>
filter(ano == 2010) |>
select(code_state = uf, popt) |>
left_join(codigos, "code_state")


pgfn_uf <- pgfn |>
group_by(abbrev_state = uf_unidade_responsavel) |>
summarise(
n = n(),
valor = sum(valor_consolidado)
) |>
left_join(populacao, "abbrev_state") |>
mutate(
n_pop = n / popt,
vl_pop = valor / popt
)

estados |>
left_join(pgfn_uf, c("abbrev_state")) |>
ggplot() +
geom_sf(aes(fill = vl_pop), color = "black", size = .1) +
scale_fill_viridis_c(
begin = .2, end = .8,
option = "A", trans = "log10"
) +
theme_void() +
labs(
title = "Dívida total / população"
)
```

<img src="man/figures/README-unnamed-chunk-5-1.png" width="100%" />

### No tempo

``` r
pgfn_mes <- pgfn |>
mutate(data = lubridate::floor_date(data_inscricao, "month")) |>
filter(data >= "2008-01-01") |>
count(data)

pgfn_mes |>
ggplot(aes(x = data, y = n/1e3)) +
geom_line(size = 1) +
theme_minimal() +
scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
labs(
x = "Mês", y = "Quantidade (milhares)",
title = "Quantidade de inscrições ao longo dos anos"
)
```

<img src="man/figures/README-unnamed-chunk-6-1.png" width="100%" />

## Modelo

``` r

library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
library(fable)
#> Carregando pacotes exigidos: fabletools


pgfn_tsibble <- pgfn_mes |>
mutate(data = yearmonth(data), n = sqrt(n/1e3)) |>
as_tsibble(index = data)

fit <- pgfn_tsibble |>
model(
model = ARIMA(n ~ pdq(2,1,2) + PDQ(1,1,1))
)

fit |>
forecast(h = 12) |>
mutate(.mean = (.mean^2), n = (n^2)) |>
autoplot(pgfn_tsibble |> mutate(n = (n^2))) +
theme_minimal() +
labs(
x = "Mês",
y = "Quantidade (milhares)",
title = "Quantidade de inscrições ao longo dos anos"
)
```

<img src="man/figures/README-unnamed-chunk-7-1.png" width="100%" />

## Apresentação

Link da apresentação
[aqui](https://docs.google.com/presentation/d/1sFtU7FqHGEV7OOjBLaGT7dh5WQNL3EhuMOAf_p6y3zY/edit?usp=sharing).
1 change: 0 additions & 1 deletion data-raw/ibdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ arquivos <- fs::dir_ls("data-raw/pgfn")

# leitura e arrumacao -----------------------------------------------------


pgfn_raw <- map_dfr(
arquivos,
read_delim,
Expand Down
Binary file added man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 892987d

Please sign in to comment.