# 312_Cap3_Matriculas_Total_Serie_Longa # ============================================================================== # Capítulo 3 (0302-pt), marcador "gráficos do educabr2": crescimento do total # de matrículas de graduação, 1933–2024, em milhões, em escala linear e log. # # DECISÃO DO AUTOR (2026-10-12, terceira rodada): só o total aqui. A divisão # público/privado já está na @fig-crescimento-matriculas-setor-governo (223) e # a discussão das proporções fica para outra figura (rascunhos no 311). # Sem marcos de leis desenhados no gráfico. # # QUARTA RODADA (2026-10-13): o autor voltou à ideia da série completa com o # total E as linhas do setor público e do privado, só com linhas (sem área # colorida nem empilhada). O total vai de 1933; os setores entram em 1973, # primeiro ano da divisão contínua (1971–72 não têm divisão; ver 221 para # os marcos setoriais anteriores, que não fecham com o total). # # Por que linear E log: na escala linear o século inteiro antes de 1995 vira # uma linha rente ao zero (23 mil em 1933 contra 10,2 milhões em 2024); na # escala log as taxas de crescimento ficam comparáveis entre períodos, e a # expansão dos anos 1960–70, a queda de 1981–82 e a estagnação até 1995 # aparecem. Os dois painéis dividem o mesmo eixo X. # # DADOS: mesma base e mesmas regras do 221 (data_tertiary_v6_clean.xlsx do # educabr2, prioridade de fonte CENSUP > Sinopse > Kang > Maduro > Durham). # - Começa em 1933, primeiro ano da série anual contínua (1908–1912 existem, # mas há um buraco de 1913 a 1932). # - 2002 sem total publicado: usa o total presencial (como no 221). # # RASCUNHOS (Fase 1, output/graphs/, gitignored): # D — dois painéis empilhados: A. linear; B. log. # L — só linear. G — só log. # ============================================================================== library(readxl) library(dplyr) library(tidyr) library(stringr) library(ggplot2) library(patchwork) source(here::here("shared-pipeline", "utils", "plot_theme.R")) theme_set(thesis_theme()) # Planilha-fonte versionada no repositorio publico do pacote educabr2 # (data-raw/sources/tertiary_multisource/). Baixada uma vez para data-raw/. CAMINHO_V6 <- here::here("data-raw", "educabr2", "data_tertiary_v6_clean.xlsx") if (!file.exists(CAMINHO_V6)) { dir.create(dirname(CAMINHO_V6), showWarnings = FALSE, recursive = TRUE) download.file( paste0("https://raw.githubusercontent.com/mancano-tales/educabr2/main/", "data-raw/sources/tertiary_multisource/data_tertiary_v6_clean.xlsx"), CAMINHO_V6, mode = "wb", quiet = TRUE ) } stopifnot(file.exists(CAMINHO_V6)) source_priority <- function(src) { case_when( str_starts(src, "CENSUP") ~ 1, str_starts(src, "Sinopse_CENSUP") ~ 2, str_starts(src, "educacao") ~ 3, str_detect(src, "Kang-Paese-Felix") ~ 4, str_detect(src, "MaduroJunior") ~ 5, str_detect(src, "Durham") ~ 6, TRUE ~ 7 ) } ANO_INICIO <- 1933 ANO_SETOR <- 1973 total <- read_excel(CAMINHO_V6) |> filter(enrollment_type %in% c( "Total", "Public", "Private", "Total_Presencial", "Public_Presencial", "Private_Presencial" )) |> mutate(src_p = source_priority(data_source)) |> arrange(src_p) |> distinct(year_key, enrollment_type, .keep_all = TRUE) |> select(year_key, enrollment_type, numbahs) |> pivot_wider(names_from = enrollment_type, values_from = numbahs) |> arrange(year_key) |> complete(year_key = full_seq(year_key, 1)) |> mutate( Total = if_else(is.na(Total), Total_Presencial, Total), # 2002 prop_priv_presencial = Private_Presencial / Total_Presencial, Private = if_else(is.na(Private) & !is.na(prop_priv_presencial), Total * prop_priv_presencial, Private ), # 2000–2008, como no 221 Public = if_else(is.na(Public), Total - Private, Public), across(c(Public, Private), ~ if_else(year_key < ANO_SETOR, NA_real_, .x)) ) |> filter(year_key >= ANO_INICIO) |> select(ano = year_key, Total, Public, Private) stopifnot(!anyNA(total$Total)) setor <- total |> filter(ano >= ANO_SETOR) stopifnot(!anyNA(setor), all(abs(setor$Public + setor$Private - setor$Total) < 1)) # Ensino médio como quarta linha (variante M do 313, escolhida pelo autor em # 2026-10-13): matrículas de todas as idades no ensino médio, de Kang, Paese e # Felix (2021) pelo educabr2, Brasil, raça "total", 1933–2010 (a série termina # em 2010). Mostra que o ensino médio ficou parado nos anos 1980 e mais que # dobrou entre 1990 e 2004, antes da arrancada da educação terciária. medio <- educabr2::enrollment_kang_fgv |> filter( geo_level == "BR", dim_race == "total", level == "medio", indicator == "enrollment_count", year >= ANO_INICIO ) |> transmute(ano = year, serie = "Upper secondary", n = value) stopifnot(!anyNA(medio$n), !anyDuplicated(medio$ano)) CORES <- c( Total = COR_NACIONAL, Private = PALETA_QUALITATIVA[1], # como na 223 Public = PALETA_QUALITATIVA[4], "Upper secondary" = PALETA_QUALITATIVA[3] ) longo <- total |> pivot_longer(-ano, names_to = "serie", values_to = "n") |> filter(!is.na(n)) |> bind_rows(medio) |> mutate(serie = factor(serie, levels = names(CORES))) # Grade manual: o helper do educabr2 põe 1940 colado em 1933 e 2020 em 2024. eixo_x <- scale_x_continuous( breaks = c(1933, 1950, 1970, 1990, 2010, 2024), expand = expansion(mult = 0.02) ) base <- ggplot(longo, aes(ano, n / 1e6, colour = serie)) + geom_line(linewidth = 0.75) + scale_colour_manual(values = CORES, name = NULL) + eixo_x + labs(x = NULL) + theme(legend.position = "bottom") p_lin <- base + scale_y_continuous( breaks = seq(0, 10, 2), limits = c(0, NA), expand = expansion(mult = c(0, 0.03)) ) + labs(y = "Millions") p_log <- base + scale_y_log10( breaks = c(0.01, 0.1, 1, 10), labels = c("0.01", "0.1", "1", "10"), limits = c(0.01, 12) ) + labs(y = "Millions (log scale)") p_dupla <- ((p_lin + theme(axis.text.x = element_blank())) / p_log) + plot_layout(guides = "collect") + plot_annotation(tag_levels = "A") & theme(legend.position = "bottom") # ── LEGENDA / DRAFT PARA O QUARTO ──────────────────────────────────────────── # fig-cap: "Undergraduate enrollment by sector and upper secondary enrollment, Brazil, 1933–2024. # Source: educabr2 (Maduro Júnior 2007; Kang, Paese and Felix 2021; INEP)." # fig-label: fig-matriculas-total-serie-longa # Nota metodológica: total de matrículas de graduação, presencial e EaD; # 2002 = total presencial; setores desde 1973; 2000–2008 privado imputado # pela participação no presencial; painel A linear, B log. # Variáveis-chave: Total, Public, Private (data_tertiary_v6_clean.xlsx) # Referência cruzada no texto: @fig-matriculas-total-serie-longa # Dimensões: LARGURA_TEXTO × ALTURA_ALTA (D); ALTURA_PADRAO (L, G) # Paleta: COR_NACIONAL (total), PALETA_QUALITATIVA[1] privado, [4] público # ───────────────────────────────────────────────────────────────────────────── salvar_grafico(p_dupla, "312_Cap3_Setores_D_linear_log", altura = ALTURA_ALTA) salvar_grafico(p_lin, "312_Cap3_Setores_L_linear") salvar_grafico(p_log, "312_Cap3_Setores_G_log") # ── PROMOÇÃO (2026-10-13): versão D (linear + log) com o ensino médio ─────── finalizar_figura( plot = p_dupla, fig_label = "matriculas-setor-serie-longa", fig_cap = "Undergraduate enrollment by sector and upper secondary enrollment, Brazil, 1933–2024.", nota = paste( "Total undergraduate enrollment, in-person and distance learning, its", "public and private components (from 1973, the first year of a continuous", "sector series) and upper secondary enrollment at all ages (to 2010);", "panel A on a linear scale, panel B on a logarithmic scale. Sources by", "period and the gaps filled in" ), apendice = "sec-fignote-matriculas-setor-serie-longa", fonte = paste( "IBGE, Estatísticas do Século XX; Maduro Júnior (2007);", "Kang, Paese and Felix (2021); INEP --- Sinopse and Censo da Educação", "Superior; compiled in the educabr2 package" ), script_path = here::here("posts", "matriculas-setor-serie-longa", "plot.R"), altura = ALTURA_ALTA ) print(total |> filter(ano %in% c(1933, 1945, 1960, 1968, 1970, 1975, 1980, 1981, 1982, 1990, 1995, 2000, 2010, 2024)), n = 20)