Learn R Programming

epiflows (version 0.2.1)

add_coordinates: Add/Retrieve location coordinates

Description

Adds/Retrieves longitude/latitude values to location data within an epiflows object. Coordinates are added to object's locations slot as lon and lat columns.

Usage

add_coordinates(
  x,
  coordinates = c("lon", "lat"),
  loc_column = "id",
  overwrite = FALSE
)

get_coordinates(x, ...)

# S3 method for epiflows get_coordinates(x, location = NULL, ...)

Value

An updated epiflows object.

Arguments

x

An epiflows object.

coordinates

Either names of the appended columns with longitudes and latitudes, respectively (default: "lon" and "lat") or a data frame with longitude and latitude columns.

loc_column

Name of the column where location names are stored (default: "country").

overwrite

If TRUE, retrieves all geocodes, even those already retrieved. If FALSE (default), overwrites only NAs.

...

unused

location

a character specifying a single location to return as a vector of coordinates. You cannot specify multiple locations with this parameter. Defaults to `NULL`, indicating all locations.

Author

Pawel Piatkowski, Salla Toikkanen, Zhian Kamvar

See Also

map_epiflows(); plot.epiflows(); get_locations(); get_vars(); global_vars()

Examples

Run this code

# Setting up the data
data("Brazil_epiflows")
data("YF_coordinates")
get_coordinates(Brazil_epiflows) # no coordinates yet
ef <- add_coordinates(Brazil_epiflows, YF_coordinates[-1])
get_coordinates(ef)
get_coordinates(ef, location = "Espirito Santo") # coordinates for Espirito Santo
if (interactive()) {
  # You can use google maps' geocode functionality if you have a decent 
  # internet connection
  # NOTE: you may need to authenticate with Google Maps API beforehand
  # using ggmap::register_google()
  ef2 <- add_coordinates(Brazil_epiflows, loc_column = "id")
  ef2
}

Run the code above in your browser using DataLab