Atualizado em 2025-11-26 18:35:46.811136

Demográficos

N crianças

N bruto

1171

N t2

154

Gráfico

Dados gerais

Descritivas idade

Descritivas sexo

Localidade

Dados de localidade

Estado

Cidade

Respostas descuidadas

Descritivas das perguntas e itens

Perguntas de atenção

Contagem de respostas repetidas

Grafico relacao de idade com atenção

Perguntas de atenção por idade

---
title: "Acompanhamento coleta autorrelato ACENNA"
output: 
  flexdashboard::flex_dashboard:
    theme: yeti
    social: menu
    source_code: embed
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```

```{r}
pacman::p_load(readxl, tidyverse, DT, lavaan,easystats)

source("https://raw.githubusercontent.com/Pedro-SR-Martins/my_funs/refs/heads/main/descriptive")
```

```{r}
codebook <- readxl::read_excel("codebook.xlsx", sheet = "dicscalesself")
```


```{r}
fulldata <- read_excel("Base_esf_alunos.xlsx") %>% filter(time == "t1") %>% filter(child_age > 9 & child_age < 18) %>%
  mutate(across(where(is.numeric), ~na_if(.x, 999))) %>% mutate(attentioncheck = case_when(esfs_13 == 2 & esfs_26 == 5 ~ 1,TRUE ~0)) %>% filter(attentioncheck == 1)
```


Atualizado em `r Sys.time()`


# Demográficos {data-icon="fa-users"} 

## N crianças

### N bruto

```{r}
initialn <- fulldata %>% select(child_age) %>% tally() %>% pull()
valueBox(value = initialn, icon = "fa-child", caption = "Total de crianças cumprindo o critério de idade e atenção", color = "#E39140")
```

### N t2
```{r}
t2n <- read_excel("Base_esf_alunos.xlsx") %>% filter(time == "t2") %>% tally() %>% pull()
valueBox(value = t2n, icon = "fa-clock-rotate-left", caption = "Total de crianças com reteste", color = "#879BA1")
```

### Gráfico

```{r}
p1 <- fulldata %>% 
  ggplot(aes(x=child_age))+
  geom_bar(color = "black", fill = "#84CCE1")+
  geom_text(aes(label=after_stat(count)),stat="count", 
            nudge_y=3,size = 4)+
  # geom_density(lwd = 1, color = "black")+
  scale_x_continuous(limits = c(9.5,17.5), breaks = c(10,11,12,13,14,15,16,17),
                     expand = c(0.005,0.005))+
  scale_y_continuous(expand = c(0.005,0.005), limits = c(0,180), breaks = seq(from = 0, to = 300, by = 10))+
  theme_classic()+
  labs(x = "Idade", y = "n")+
  theme(panel.background = element_blank(), 
        axis.line = element_line(colour = "black"), 
        legend.key = element_rect(fill = "white"),
        axis.text.y = element_text(colour="black", size = 12), 
        axis.text.x = element_text(colour="black", size = 12),
        text = element_text(size = 15),
        legend.position="bottom",
        plot.title = element_text(hjust = 0.5,
                                  face="bold"))
# plotly::ggplotly(p1)
p1

```



## Dados gerais

### Descritivas idade


```{r}
fulldata %>%
  select(child_age) %>%
  describedf()%>%  
  DT::datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'excel', 'pdf'),
                           lengthMenu = list(c(10,25,50,-1),
                                             c(10,25,50,"All"))))
```


### Descritivas sexo


```{r}
fulldata %>%
  select(child_sex) %>% 
  mutate(child_sex = factor(child_sex, levels = c(1,2), labels = c("Feminino", "Masculino"))) %>% 
 count(child_sex) %>% mutate(pct = (n/sum(n))*100)%>%   DT::datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'excel', 'pdf'),
                           lengthMenu = list(c(10,25,50,-1),
                                             c(10,25,50,"All"))))
```


# Localidade {data-icon="fa-map"}

## Dados de localidade


### Estado


```{r}
pacman::p_load(sf,leaflet,geobr,ggtext)
brazil_states <- read_state(code_state = "all", year = 2020, simplified = TRUE) %>% 
  rename(state_br = abbrev_state)
mergeddata <- fulldata %>% count(statebr) %>% mutate(state_br = factor(statebr, levels = c(1,2,3), labels = c("MG", "PR","BA"))) %>% 
  # full_join(.,dicstate) %>% 
  full_join(brazil_states) %>%
  # mutate(n = case_when(is.na(n) ~ 0,
  #                      TRUE ~n)) %>% 
  mutate(region = factor(statebr, levels = c(1:5), labels = c("SUDESTE", "SUL","NORDESTE","NORTE","CENTRO-OESTE")))
# Define a color palette for the regions
region_colors <- c("NORDESTE" = "#FFD700", "NORTE" = "white", "CENTRO-OESTE" = "white", "SUDESTE" = "#FF4500", "SUL" = "#8A2BE2")


# Create the plot
ggplot() +
  geom_sf(data = mergeddata, aes(geometry = geom, fill = region), color = "black", size = 0.2) +
  scale_fill_manual(values = region_colors, name = "Region",na.value = "white") +
  geom_sf_label(data = mergeddata, aes(label = n, geometry = geom), 
                fill = "white", size = 3, #fontface = "bold"
                ) +
  theme_void()+
  theme(legend.position = "none")

# fulldata %>% 
#   select(statebr) %>% 
#   mutate(statebr = factor(statebr, levels = c(1,2,3),
#                        labels = c("Minas Gerais", "Paraná", "Bahia"))) %>% 
#   count(statebr) %>% mutate(pct = (n/sum(n))*100)%>%   DT::datatable(extensions = 'Buttons',
#             options = list(dom = 'Blfrtip',
#                            buttons = c('copy', 'excel', 'pdf'),
#                            lengthMenu = list(c(10,25,50,-1),
#                                              c(10,25,50,"All"))))
```



### Cidade


```{r}
fulldata %>% 
  select(city) %>% 
  mutate(city = factor(city, levels = c(1,2,3,4,5,6),
                       labels = c("RMBH", "Curvelo","Aguas Formosas (e região)", "São João del Rei (e região)",
                                  "Londrina", "Vitória da Conquista"))) %>% 
  count(city) %>% mutate(pct = (n/sum(n))*100)%>%   DT::datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'excel', 'pdf'),
                           lengthMenu = list(c(10,25,50,-1),
                                             c(10,25,50,"All"))))
```




# Respostas descuidadas {data-icon="fa-wrench"}

## Descritivas das perguntas e itens

### Perguntas de atenção

```{r}
read_excel("Base_esf_alunos.xlsx") %>% 
  filter(time == "t1") %>% filter(child_age > 9 & child_age < 18) %>% 
  mutate(across(where(is.numeric), ~na_if(.x, 999))) %>% 
  mutate(attentioncheck = case_when(esfs_13 == 2 & esfs_26 == 5 ~ "Passou",
                                    TRUE ~"Não passou")) %>% 
  count(attentioncheck) %>%
  DT::datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'excel', 'pdf'),
                           lengthMenu = list(c(10,25,50,-1),
                                             c(10,25,50,"All"))))
```




### Contagem de respostas repetidas


```{r}
items <- fulldata %>% 
  select(esfs_01:esfs_39) %>% 
  mutate(across(where(is.numeric), ~na_if(.x, 999))) %>% 
  mutate(attentioncheck = case_when(esfs_13 == 2 & esfs_26 == 5 ~ 1,
                                    TRUE ~0)) %>% 
  filter(attentioncheck == 1) %>% select(-attentioncheck,-esfs_13,-esfs_26)
pacman::p_load(careless)
longids <- careless::longstring(items, avg = T)
outliers <- boxplot.stats(longids$longstr, coef = 1.5)$out
janitor::tabyl(longids$longstr) %>% 
  DT::datatable(extensions = 'Buttons',
            options = list(dom = 'Blfrtip',
                           buttons = c('copy', 'excel', 'pdf'),
                           lengthMenu = list(c(10,25,50,-1),
                                             c(10,25,50,"All"))))
```

## Grafico relacao de idade com atenção

### Perguntas de atenção por idade

```{r}
read_excel("Base_esf_alunos.xlsx") %>% 
  filter(child_age > 9 & child_age < 18) %>% filter(time == "t1") %>% 
  mutate(across(where(is.numeric), ~na_if(.x, 999))) %>%
  mutate(attentioncheck = case_when(
      esfs_13 == 2 & esfs_26 == 5 ~ "Passou",
      TRUE ~ "Não passou")) %>% #filter(attentioncheck == "Passou")
  group_by(attentioncheck) %>% 
    count(child_age) %>%
    ggplot(aes(x = child_age, y = n, fill = attentioncheck)) +
      geom_col(position = position_dodge()) +
      scale_x_continuous(limits = c(9.5, 17.5),
                         breaks = 10:17,
                         expand = c(0.005, 0.005)) +
      scale_y_continuous(expand = c(0.005, 0.005), breaks = seq(from = 0, to = 300, by = 10)) +
      labs(x = "Idade", y = "Contagem", fill = "Atenção") +
      theme_classic() +
      theme(panel.background = element_blank(),
            axis.line = element_line(colour = "black"),
            axis.text = element_text(colour = "black", size = 12),
            text = element_text(size = 15),
            legend.position = "bottom",
            plot.title = element_text(hjust = 0.5, face = "bold"))
```



```{r}
p1 <- read_excel("Base_esf_alunos.xlsx") %>% 
  filter(child_age > 9 & child_age < 18) %>% filter(time == "t1") %>% 
  mutate(across(where(is.numeric), ~na_if(.x, 999))) %>%
  mutate(attentioncheck = case_when(
      esfs_13 == 2 & esfs_26 == 5 ~ "Passou",
      TRUE ~ "Não_passou")) %>% #filter(attentioncheck == "Passou")
  group_by(attentioncheck) %>% 
  count(child_age) %>% 
  pivot_wider(id_cols = child_age,names_from = attentioncheck,values_from = n) %>% 
  mutate(pct = (Não_passou/(Não_passou+Passou))*100) %>% 
    ggplot(aes(x = child_age, y = pct)) +
      geom_col(position = position_dodge(), fill = "skyblue", color = "black") +
      scale_x_continuous(limits = c(9.5, 17.5),
                         breaks = 10:17,
                         expand = c(0.005, 0.005)) +
      scale_y_continuous(expand = c(0.005, 0.005), 
                         limits = c(0, 100),
                         breaks = seq(from = 0, to = 100, by = 10)) +
      labs(x = "Idade", y = "Porcentagem que não passou", fill = "Atenção") +
      theme_classic() +
      theme(panel.background = element_blank(),
            axis.line = element_line(colour = "black"),
            axis.text = element_text(colour = "black", size = 12),
            text = element_text(size = 15),
            legend.position = "bottom",
            plot.title = element_text(hjust = 0.5, face = "bold"))
```

```{r}
# read_excel("Base_esf_alunos.xlsx") %>% 
#   filter(child_age > 9 & child_age < 18) %>% filter(time == "t1") %>% 
#   mutate(across(where(is.numeric), ~na_if(.x, 999))) %>%
#   mutate(attentioncheck = case_when(
#       esfs_13 == 2 & esfs_26 == 5 ~ 1,
#       TRUE ~ 0)) %>% 
#   select(child_age,attentioncheck) %>% correlation()
```