Skip to contents

brazil_municipality_latitude() returns the latitude of Brazilian municipalities.

Note: This function requires an active internet connection and the geobr package to be installed.

Usage

brazil_municipality_latitude(
  municipality_code,
  year = as.numeric(substr(Sys.Date(), 1, 4)),
  coords_method = "geobr",
  names = TRUE,
  ...
)

Arguments

municipality_code

An integerish vector with the IBGE codes of Brazilian municipalities. Use brazil_municipality_code() to obtain codes from municipality names and states.

year

(optional) An integerish number indicating the year of the data regarding the municipalities (default: Sys.Date() |> substr(1, 4) |> as.numeric()).

coords_method

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

names

(optional) A logical flag indicating whether to return the names of the municipalities as names of the vector (default: TRUE).

...

(optional) Additional arguments passed to brazil_municipality().

Value

A numeric vector with the latitude of the Brazilian municipalities.

Details

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

The geobr package is produced by Brazil's Institute for Applied Economic Research (IPEA) and access the Brazilian Institute of Geography and Statistics (IBGE) data. You can see a list of all geobr datasets by running geobr::list_geobr().

Examples

library(curl)

# \dontrun{
  if (has_internet()) {
    brazil_municipality_latitude(3550308)
  }
#> São Paulo-SP 
#>  -23.5673865 
# }

# \dontrun{
  if (has_internet()) {
    brazil_municipality_latitude(c(3550308, 3500204))
  }
#> São Paulo-SP    Adolfo-SP 
#> -23.56738650 -21.23272978 
# }

# \dontrun{
  if (has_internet()) {
    brazil_municipality_latitude(c(3550308, 1000, 3500204))
  }
#> São Paulo-SP         <NA>    Adolfo-SP 
#> -23.56738650           NA -21.23272978 
# }

# \dontrun{
  if (has_internet()) {
    brazil_municipality_latitude(c(3550308, NA, 3500204))
  }
#> São Paulo-SP         <NA>    Adolfo-SP 
#> -23.56738650           NA -21.23272978 
# }