Search code examples
rgoogle-mapsgoogle-maps-api-3ggplot2ggmap

ggmap / ggplot error when plotting points on a ggmap: [arguments imply differing number of rows]


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

Solution

  • 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)