0

I am trying to plot points for countries on a map (so I can eventually make a network style map) of Argentine exports. However, I don't know how to convert the country names to latitude and longitude. I tried using geocode, but it says NA for the latitude and longitude values and I get a "geocode failed with status REQUEST_DENIED, location = "USA"" error. Is it an error with my API? Do I need to put my API key in the geocode statement? Or how does it know to access the geocode? I think this is my error, but I am not sure. Is there an easy way to fix this? Or a different package I can use?

library(maps)
library(ggmap)
library(ggplot2)
new <- data_frame(city = c("France", "Brazil", "Uruguay")) %>%
    mutate_geocode(city)
Caroline
  • 41
  • 3

2 Answers2

0

This is a recent issue I think where Google tightened control over use of their geocoding service due to excessive traffic, now requiring API registration. This github page and this stack question seem to have solutions for getting it working again.

Alternatively, you can use dsk as a secondary source for geocode requests, though I don't know how accurate the figures are.

new <- data_frame(city = c("France", "Brazil", "Uruguay")) %>%
    mutate_geocode(city, source = "dsk")

    city lon lat
1  France   2  46
2  Brazil -55 -10
3 Uruguay -56 -33
Nautica
  • 2,004
  • 1
  • 12
  • 35
0

Presuming you have google maps API key already,

library(ggmap)
register_google(key = " ") 

then test if you can plot

ggmap(get_map("France", "Brazil", "Uruguay"))

If you cant its probably related to your API key not being active or wrong

Ulug Toprak
  • 1,172
  • 1
  • 10
  • 21
  • When I try to test it with this it says "Error in register_google(key = "...") : could not find function "register_google"". I don't know why it isn't recognizing the register_google function. Do you I need to add a package? – Caroline Jan 24 '19 at 18:50
  • Restart R Studio and run `sessionInfo()` this should give you the version of the `ggmap` loaded. Add it to your question pls – Ulug Toprak Jan 25 '19 at 09:33