jerH
jerH

Reputation: 1299

ggmap and spatial data plotting issue

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?

Upvotes: 0

Views: 62

Answers (1)

Dave2e
Dave2e

Reputation: 24139

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

Upvotes: 1

Related Questions