-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
132 lines (108 loc) · 2.81 KB
/
README.Rmd
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
123
124
125
126
127
128
129
130
131
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
echo = FALSE
)
library(magrittr)
```
```{r}
yaml_to_tibble <- function(file) {
rmarkdown::yaml_front_matter(file) |>
purrr::map(paste, collapse = "|") |>
tibble::as_tibble() |>
dplyr::mutate(arquivo = file)
}
grafico_freq <- function(tab, var) {
tab |>
dplyr::pull({{var}}) |>
stringr::str_split(pattern = "\\|") |>
purrr::flatten_chr() |>
tibble::enframe("name", "variavel") |>
dplyr::count(variavel) |>
dplyr::mutate(variavel = forcats::fct_reorder(variavel, n)) |>
ggplot2::ggplot(ggplot2::aes(x = n, y = variavel)) +
ggplot2::geom_col(fill = "orange") +
ggplot2::geom_label(ggplot2::aes(label = n)) +
ggplot2::theme_minimal() +
ggplot2::labs(y = "", x = "Frequência")
}
```
```{r}
arquivos <- list.files("content/posts/", pattern = ".Rmd$", full.names = TRUE)
tab <- arquivos |>
purrr::map_dfr(yaml_to_tibble) |>
dplyr::filter(is.na(draft) | draft == "FALSE") |>
dplyr::mutate(categories = tolower(categories)) |>
dplyr::mutate(author = stringr::str_replace(author, "Beatriz Milz", "Beatriz"))
```
## Número de posts: `r dplyr::n_distinct(tab$arquivo)`
## Por autoria
```{r}
grafico_freq(tab, author)
```
## Por categoria
```{r}
grafico_freq(tab, categories)
```
## Por ano
```{r}
tab |>
dplyr::mutate(
date = as.Date(date),
ano = lubridate::year(date)
) |>
grafico_freq(ano) +
ggplot2::coord_flip() +
ggplot2::scale_y_discrete(limits = as.character(2017:lubridate::year(Sys.Date())))
```
## Por mês/ano
```{r}
tab |>
dplyr::mutate(
date = as.Date(date),
ano = lubridate::year(date),
mes = lubridate::month(date),
mes_ano = lubridate::make_date(ano, mes, 1)
) |>
dplyr::count(mes_ano) |>
ggplot2::ggplot(ggplot2::aes(x = mes_ano, y = n)) +
ggplot2::geom_col(fill = "orange") +
ggplot2::theme_minimal() +
ggplot2::labs(x = "", y = "Frequência")
```
## Por mês
```{r}
tab |>
dplyr::mutate(
date = as.Date(date),
mes = lubridate::month(date)
) |>
grafico_freq(mes) +
ggplot2::coord_flip() +
ggplot2::scale_y_discrete(limits = as.character(1:12))
```
## Autoria vs categoria
```{r}
tab |>
dplyr::filter(!stringr::str_detect(author, "\\|")) |>
dplyr::group_by(author) |>
dplyr::filter(dplyr::n() >= 10) |>
dplyr::count(author, categories) |>
ggplot2::ggplot(ggplot2::aes(x = n, y = author)) +
ggplot2::geom_col(fill = "orange") +
ggplot2::facet_wrap(dplyr::vars(categories)) +
ggplot2::theme_minimal() +
ggplot2::labs(y = "", x = "Frequência")
```
## Posts aposentados
```{r}
tab |>
dplyr::filter(retired == "TRUE") |>
dplyr::select(date, title, author) |>
knitr::kable()
```