0

The following code works fine:

library(ggmap)
mp2 <- ggmap::get_map(location="South America", zoom = 4, source="google")

ggmap(mp2) +
  geom_point(aes(c(-60), c(-1)), size=15) # plot one single point on map

generating this:

code that works

Though the following won't behave as expected for some reason:

ggmap(mp2) +
  geom_point(aes(c(-60, -65, -62), c(-1, -5, -10)))

giving me the following error:

Error in data.frame(x = c(-60, -65, -62), y = c(-1, -5, -10), PANEL = c(1L,  : 
  arguments imply differing number of rows: 3, 4
4
  • using traceback() you can confirm that ggmap internally creates vectors of latitudes and longitudes in line 3: print.ggplot(list(data = list(lon = c(-83.5725316875, -27.3225316875, -83.5725316875, -27.3225316875), lat = c(-34.656848886632, -34.656848886632, 18.9102814177176, 18.9102814177176)) Commented May 9, 2014 at 21:46
  • Hmmm I see... These are the 4 corners of the ggmap. Commented May 9, 2014 at 22:06
  • Your first block code does not work any longer. May you test it and confirm it? Commented Oct 18, 2016 at 3:40
  • @OmarGonzales Try "Brazil" instead of "South America", it works for some reason. Commented Oct 18, 2016 at 8:09

1 Answer 1

2

this should work

df <- data.frame(lon=c(-60, -65, -62), lat = c(-1, -5, -10))
ggmap(mp2) +
  geom_point(aes(x = lon, y = lat), size = 10, data = df)
Sign up to request clarification or add additional context in comments.

1 Comment

It is my understanding that ggplot is expecting the get the data from data.frames, performing better (easier) with long formatted ones. Without the data.frame ggplot will internally genarate an error: stop("ggplot2 doesn't know how to deal with data of class ", class(model), call. = FALSE).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.