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
Dan
  • 1,711
  • 2
  • 24
  • 39
  • 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))` – Silence Dogood May 09 '14 at 21:46
  • Hmmm I see... These are the 4 corners of the ggmap. – Dan May 09 '14 at 22:06
  • Your first block code does not work any longer. May you test it and confirm it? – Omar Gonzales Oct 18 '16 at 03:40
  • @OmarGonzales Try "Brazil" instead of "South America", it works for some reason. – Dan Oct 18 '16 at 08:09

1 Answers1

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)
Paulo E. Cardoso
  • 5,778
  • 32
  • 42
  • 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)`. – Paulo E. Cardoso May 09 '14 at 22:15