Skip to contents

get_brazil_municipality() returns a tibble with data about Brazilian municipalities.

Usage

get_brazil_municipality(
  municipality = NULL,
  state = NULL,
  year = lubridate::year(Sys.Date()),
  coords_method = "geobr",
  force = FALSE
)

Arguments

municipality

(optional) A character vector with the name of the municipalities. If NULL the function returns all municipalities (default: NULL).

state

(optional) A character vector with the name of the states (default: NULL).

year

(optional) An integerish number indicating the year of the data regarding the municipalities (default: Sys.Date() |> lubridate::year()).

coords_method

(optional) A string indicating the method to retrieve the latitude and longitude coordinates of the municipalities. Options are:

force

(optional) A logical flag indicating whether to force the download of the data again (default: FALSE).

Value

A tibble with the following columns:

  • region_code: The region code.

  • region: The region name.

  • state_code: The state code.

  • state: The state name.

  • federal_unit: The state abbreviation.

  • municipality_code: The municipality code.

  • municipality: The municipality name.

  • latitude: The municipality latitude.

  • longitude: The municipality longitude.

Details

The data from this function is based on data from the Brazilian Institute of Geography and Statistics (IBGE) via the geobr and geocodebr R packages.

Both packages are produced by Brazil's Institute for Applied Economic Research (IPEA) and access the Brazilian Institute of Geography and Statistics (IBGE) data.

Examples

get_brazil_municipality() |> dplyr::glimpse()
#> ! The closest map year to 2025 is 2022. Using year 2022 instead.
#> Using year/date 2022
#> Rows: 5,570
#> Columns: 9
#> $ region_code       <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
#> $ region            <chr> "North", "North", "North", "North", "North", "North"…
#> $ state_code        <int> 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
#> $ state             <chr> "Rondônia", "Rondônia", "Rondônia", "Rondônia", "Ron…
#> $ federal_unit      <chr> "RO", "RO", "RO", "RO", "RO", "RO", "RO", "RO", "RO"…
#> $ municipality_code <dbl> 1100015, 1100023, 1100031, 1100049, 1100056, 1100064…
#> $ municipality      <chr> "Alta Floresta D'Oeste", "Ariquemes", "Cabixi", "Cac…
#> $ latitude          <dbl> -11.935540, -9.908463, -13.499763, -11.433865, -13.1…
#> $ longitude         <dbl> -61.99982, -63.03327, -60.54431, -61.44294, -60.8184…

get_brazil_municipality(municipality = "Belém")
#> # A tibble: 3 × 9
#>   region_code region    state_code state   federal_unit municipality_code
#>         <int> <chr>          <int> <chr>   <chr>                    <dbl>
#> 1           1 North             15 Pará    PA                     1501402
#> 2           2 Northeast         25 Paraíba PB                     2501906
#> 3           2 Northeast         27 Alagoas AL                     2700805
#> # ℹ 3 more variables: municipality <chr>, latitude <dbl>, longitude <dbl>

get_brazil_municipality(municipality = "Belém", state = "Pará")
#> # A tibble: 1 × 9
#>   region_code region state_code state federal_unit municipality_code
#>         <int> <chr>       <int> <chr> <chr>                    <dbl>
#> 1           1 North          15 Pará  PA                     1501402
#> # ℹ 3 more variables: municipality <chr>, latitude <dbl>, longitude <dbl>

get_brazil_municipality(municipality = c("Belém", "São Paulo"))
#> # A tibble: 4 × 9
#>   region_code region    state_code state     federal_unit municipality_code
#>         <int> <chr>          <int> <chr>     <chr>                    <dbl>
#> 1           1 North             15 Pará      PA                     1501402
#> 2           2 Northeast         25 Paraíba   PB                     2501906
#> 3           2 Northeast         27 Alagoas   AL                     2700805
#> 4           3 Southeast         35 São Paulo SP                     3550308
#> # ℹ 3 more variables: municipality <chr>, latitude <dbl>, longitude <dbl>