Fazer um mapa do Estado do RJ da variável Esperancadevida da base de dados BasesMunicipios.xlsx.

Para isso, você precisará usar o comando: library(geobr)

desenho_rio_municipio = read_municipality(code_muni = “RJ”, showProgress = FALSE)

library(readxl)
 BasesMunicipios <- read_excel("C:/Users/dila/Desktop/ESTATÍSTICA/Base_de_dados-master/BasesMunicipios.xlsx")
library(geobr)
## Loading required namespace: sf
desenho_rio_municipio = read_municipality(code_muni = "RJ", showProgress = FALSE)
## Using year 2010

combinar dados

BasesMunicipios$`COD IBGE2` = as.numeric(BasesMunicipios$`COD IBGE2`)

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
BasesMunicipios = BasesMunicipios %>% rename(code_muni=`COD IBGE2`)
mapa_municipios = desenho_rio_municipio %>% left_join(BasesMunicipios)
## Joining with `by = join_by(code_muni)`
summary(BasesMunicipios$Esperancadevida)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   71.93   73.26   73.74   73.96   74.83   76.27

ver dados

library(ggplot2)
mapa1 = ggplot() +
  geom_sf(data=mapa_municipios, aes(fill=Esperancadevida)) +
  scale_fill_distiller(palette = "orange",direction = 1, name="Esperança de vida", 
                       limits = c(71.93,76.27))
## Warning in pal_name(palette, type): Unknown palette orange
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
ggplotly(mapa1)

análise: