add_coordinates.Rd
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.
add_coordinates(x, coordinates = c("lon", "lat"), loc_column = "id", overwrite = FALSE) get_coordinates(x, ...) # S3 method for epiflows get_coordinates(x, location = NULL, ...)
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. |
An updated epiflows
object.
# Setting up the data data("Brazil_epiflows") data("YF_coordinates") get_coordinates(Brazil_epiflows) # no coordinates yet#> NULLef <- add_coordinates(Brazil_epiflows, YF_coordinates[-1]) get_coordinates(ef)#> id lon lat #> 1 Espirito Santo -40.308863 -19.18342 #> 2 Minas Gerais -44.555031 -18.51218 #> 3 Rio de Janeiro -43.172897 -22.90685 #> 4 Sao Paulo -46.633309 -23.55052 #> 5 Southeast Brazil -46.209155 -20.33318 #> 6 Argentina -63.616672 -38.41610 #> 7 Chile -71.542969 -35.67515 #> 8 Germany 10.451526 51.16569 #> 9 Italy 12.567380 41.87194 #> 10 Paraguay -58.443832 -23.44250 #> 11 Portugal -8.224454 39.39987 #> 12 Spain -3.749220 40.46367 #> 13 United Kingdom -3.435973 55.37805 #> 14 United States of America -95.712891 37.09024 #> 15 Uruguay -55.765835 -32.52278get_coordinates(ef, location = "Espirito Santo") # coordinates for Espirito Santo#> [1] -40.30886 -19.18342# You can use google maps' geocode functionality if you have a decent # internet connection ef2 <- add_coordinates(Brazil_epiflows, loc_column = "id")#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Espirito Santo"#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Minas Gerais"#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Rio de Janeiro"#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Sao Paulo"#>#>#>#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Germany"#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Italy"#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Paraguay"#>#>#>#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Spain"#>#>#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "United Kingdom"#>#>#>#>ef2#> #> /// Epidemiological Flows // #> #> // class: epiflows, epicontacts #> // 15 locations; 100 flows; directed #> // optional variables: pop_size, duration_stay, num_cases, first_date, last_date, coordinates #> #> // locations #> #> # A tibble: 15 x 8 #> id location_popula… num_cases_time_… first_date_cases last_date_cases #> * <chr> <dbl> <dbl> <fct> <fct> #> 1 Espi… 3973697 2600 2017-01-04 2017-04-30 #> 2 Mina… 20997560 4870 2016-12-19 2017-04-20 #> 3 Rio … 16635996 170 2017-02-19 2017-05-10 #> 4 Sao … 44749699 200 2016-12-17 2017-04-20 #> 5 Sout… 86356952 7840 2016-12-17 2017-05-10 #> 6 Arge… NA NA <NA> <NA> #> 7 Chile NA NA <NA> <NA> #> 8 Germ… NA NA <NA> <NA> #> 9 Italy NA NA <NA> <NA> #> 10 Para… NA NA <NA> <NA> #> 11 Port… NA NA <NA> <NA> #> 12 Spain NA NA <NA> <NA> #> 13 Unit… NA NA <NA> <NA> #> 14 Unit… NA NA <NA> <NA> #> 15 Urug… NA NA <NA> <NA> #> # ... with 3 more variables: length_of_stay <dbl>, lon <dbl>, lat <dbl> #> #> // flows #> #> # A tibble: 100 x 3 #> from to n #> <chr> <chr> <dbl> #> 1 Espirito Santo Italy 2828. #> 2 Minas Gerais Italy 15714. #> 3 Rio de Janeiro Italy 8164. #> 4 Sao Paulo Italy 34039. #> 5 Southeast Brazil Italy 76282. #> 6 Espirito Santo Spain 3270. #> 7 Minas Gerais Spain 18176. #> 8 Rio de Janeiro Spain 9443. #> 9 Sao Paulo Spain 39371. #> 10 Southeast Brazil Spain 88231. #> # ... with 90 more rows #>