library(sidrar)
library(geobr)
library(sf)
library(dplyr)
library(ggplot2)
library(rsconnect)
library(shiny)Mapa do Brasil por UF - População Estimada (Fonte: IBGE/SIDRA - Tabela 6579)
População residente
O intuito deste blog é analisar a população residente estimada do Brasil por Unidade da Federação no ano de 2024.
- CARREGAMENTO DOS PACOTES
- COLETA DE DADOS
Para isso, os dados foram obtidos do IBGE por meio do pacote sidrar, utilizando a Tabela 6579 e a variável 9324, que traz as estimativas populacionais oficiais para os 27 estados.
dados_pop <- get_sidra(x = 6579, variable = 9324, period = "2024", geo = "State") - TRATAMENTO DOS DADOS
dados_pop_limpo <- dados_pop %>%
select(nome_uf = `Unidade da Federação`,
code_state = `Unidade da Federação (Código)`,
populacao = Valor) %>%
mutate(code_state = as.numeric(code_state))- LEITURA DO MAPA E JUNÇÃO
mapa_ufs <- read_state(year = 2020, showProgress = FALSE)mapa_final <- left_join(mapa_ufs, dados_pop_limpo, by = "code_state")- MAPA
ggplot(mapa_final) +
geom_sf(aes(fill = populacao)) +
scale_fill_viridis_c(name = "População\nestimada",
labels = scales::comma_format(big.mark = ".", decimal.mark = ",")
) +
labs(title = "População Residente Estimada por Unidade da Federação",
subtitle = "Brasil, 2024") +
theme_minimal() +
theme(plot.title = element_text(face = "bold", size = 13),
plot.subtitle = element_text(size = 10),
legend.position = "right")- GRÁFICO DE BARRAS
dados_pop_limpo |>
mutate(nome_uf = reorder(nome_uf, populacao)) |>
ggplot(aes(x = nome_uf, y = populacao, fill = populacao)) +
geom_col(show.legend = FALSE) +
scale_fill_viridis_c() +
scale_y_continuous(
labels = scales::label_number(big.mark = ".", decimal.mark = ",")
) +
coord_flip() +
labs(
title = "População Estimada por UF — Brasil (2024)",
x = NULL,
y = "População",
caption = "Fonte: IBGE/SIDRA, Tabela 6579"
) +
theme_minimal(base_size = 11)