0

I am trying to update some old code that I inherited from before the Google API days to do a fairly simple (I think) plot.

By the time I get to the plot, my data consists of 50 triplets of latitude, longitude, and $K amount of investment at that location.

head(investData)
  amount latitude longitude
1 1404   42.45909 -71.27556
2 1      42.29076 -71.35368
3 25     42.34700 -71.10215
4 1      40.04492 -74.58916
5 15     43.16431 -75.51130

at this point I use the following

register_google(key = "###myKey###")   #my actual key here

USAmap <- qmap("USA",zoom=4)

USAmap + geom_point(data=investData, aes(x=investData$longitude, y=investData$latitude,size=investData$amount))

I've been fighting all ay with establishing accounts and enabling APIs with Google, so it's entirely possible I've simply failed to enable something I need to. I have the geocoding, geolocation, and maps static APIs enabled.

I get the following output at the console

Source : https://maps.googleapis.com/maps/api/staticmap?center=USA&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
Source : https://maps.googleapis.com/maps/api/geocode/json?address=USA&key=xxx

But I get no plot.

if I simply run

qmap("USA", zoom=4)

I get the map I expect. But when I try to overlay the investment data I get zilch. I'm told by the folks who handed this to me that it worked in 2017...

Any idea where I'm going wrong?

jerH
  • 1,085
  • 1
  • 12
  • 30
  • 1
    I can't reproduce but try this instead: `print(USAmap + geom_point(data=investData, aes(x=longitude, y=latitude,size=amount)))` – Dave2e Feb 19 '20 at 03:35
  • 1
    Can't reproduce either. [Don't use `$` inside `aes`](https://stackoverflow.com/questions/32543340/issue-when-passing-variable-with-dollar-sign-notation-to-aes-in-combinatio). Beyond that, update packages, restart R, and try again? – camille Feb 19 '20 at 04:03
  • print did it....if you want to make that an answer I'll happily accept it. And yeah, not sure why the $ were in the aes. I'll fix that too. – jerH Feb 19 '20 at 04:07

1 Answers1

1

If you are running your script via the source function or with the run command (from inside RStudio) you must explicitly call the print function on your ggplot commands. For example:

print(USAmap + geom_point(data=investData, aes(x=longitude, y=latitude,size=amount)))

As Camille mentioned, no need for the $ inside the aes

Dave2e
  • 22,192
  • 18
  • 42
  • 50