add_coordinates {epiflows} | R Documentation |
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 class 'epiflows'
get_coordinates(x, location = NULL, ...)
Arguments
x |
An |
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. |
Value
An updated epiflows
object.
Author(s)
Pawel Piatkowski, Salla Toikkanen, Zhian Kamvar
See Also
map_epiflows()
; plot.epiflows()
; get_locations()
; get_vars()
;
global_vars()
Examples
# 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
}