Exercício final do curso de introdução aos indicadores sociais com R

Objetivo: Unir as bases de dados do Censo demográfico (1991, 2000 e 2010) e da PNAD Contínua, com o intúito de verificar a evolução, ao longo do tempo, da taxa de evasão escolar no ensino fundamental, em relação ao IDHM.

1. Carregar as bibliotecas que serĂŁo utilizadas

library(esquisse)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## âś” ggplot2 3.4.0      âś” purrr   1.0.1 
## âś” tibble  3.1.8      âś” dplyr   1.0.10
## âś” tidyr   1.3.0      âś” stringr 1.5.0 
## âś” readr   2.1.3      âś” forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::lag()    masks stats::lag()
library(ggplot2)
library(readxl)
library(summarytools)
## 
## Attaching package: 'summarytools'
## 
## The following object is masked from 'package:tibble':
## 
##     view

2. Carregar as bases de dados (http://www.atlasbrasil.org.br/acervo/biblioteca):

  • Atlas 2013_municipal_estadual_Brasil
munic <- read_excel("~/Library/CloudStorage/OneDrive-Pessoal/0.R_Projects/Teste/Atlas.xlsx", 
    sheet = "MUN 91-00-10")
  • Registro Administrativo total 2012 a 2017
educa <- read_excel("~/Library/CloudStorage/OneDrive-Pessoal/0.R_Projects/Teste/PNUD.xlsx", 
    sheet = "MUNICĂŤPIO")

3. Selecionar as variáveis que desejamos analisar, em cada uma das bases de dados e classificar as variáveis de interesse:

munic %>% 
  select(ANO, GINI, PIND, IDHM, IDHM_E, IDHM_R, Codmun7, POP, pesoRUR, pesotot, pesourb) %>% 
  mutate(classe_pop = case_when(
    (POP < 5001) ~ "1) Até 5.000",
    (POP > 5000 & POP < 20001) ~ "2) 5.001 a 20.000",
    (POP > 20000 & POP < 100001) ~ "3) 20.001 a 100.000", 
    (POP > 100000 & POP < 500001) ~ "4) 100.001 a 500.00",
    (POP > 500000) ~ "5) Mais de 500.00"
    )) %>%
  mutate(Classe_idhm = case_when( 
    (IDHM < 0.5) ~ "Muito baixo",
    (IDHM >= 0.5 & IDHM < 0.6) ~ "Baixo",
    (IDHM >= 0.6 & IDHM < 0.7) ~ "Médio",
    (IDHM >= 0.7 & IDHM < 0.8) ~ "Alto",
    (IDHM >= 0.8) ~ "Muito Alto",
    )) -> munic2

educa %>% 
  select(TTREVA_EF_PRI, TTREVA_EF_PUB, IBGE7, TTREVA_EF_TOTAL) -> educa2

4. Unir as bases

munic2 %>% 
  full_join(educa2, by = c("Codmun7"="IBGE7")) %>% 
  na.omit() -> join_munic_edu

5. Gerar o gráfico

ggplot(join_munic_edu) +
  aes(x = IDHM, y = TTREVA_EF_TOTAL, colour = Classe_idhm) +
  geom_point(shape = "circle", size = 1.5) +
  scale_color_hue(direction = -1) +
  theme_minimal() +
  facet_wrap(vars(ANO))