Error: Discrete value supplied to continuous scale

user3720904 picture user3720904 · Jun 9, 2014 · Viewed 13.1k times · Source

I'm using ggmap to work on a map of madagascar

myMap <- get_map(location=k, source="stamen", maptype="toner", crop=FALSE, 
                 zoom=16)

and to plot points on that map from an x y lat/lon grid

ggmap(myMap) + geom_point(data=GPS, aes(x = 'Lon', y ='Lat'))
ggplot(data=GPS, aes(x=Lon,y=Lat)) + geom_point()

from data that look like this

 Tree.ID       Type       Species       Lat      Lon Foraged Plot
       7   deadwood      Dracaena -21.37413 47.86700       N    1
       8   deadwood       Bivinia -21.37408 47.86696       N    1
       9   deadwood Beilschmiedia -21.37396 47.86691       N    1
      10 live trunk        Ocotea -21.37410 47.86690       N    1
      12   deadwood   Tambourissa -21.37418 47.86696       N    1
      13 live trunk      Canarium -21.37422 47.86691       N    1

But I get this error:

Error: Discrete value supplied to continuous scale

What should I do?

Answer

jbaums picture jbaums · Jun 11, 2014

You're passing the character strings "Lon" and "Lat" to x and y rather than passing Lon and Lat themselves. Take out the quotes and you should be fine.

d <- read.table(header=T, text='
 Tree.ID      Type       Species       Lat      Lon Foraged Plot
       7  deadwood      Dracaena -21.37413 47.86700       N    1
       8  deadwood       Bivinia -21.37408 47.86696       N    1
       9  deadwood Beilschmiedia -21.37396 47.86691       N    1
      10 livetrunk        Ocotea -21.37410 47.86690       N    1
      12  deadwood   Tambourissa -21.37418 47.86696       N    1
      13 livetrunk      Canarium -21.37422 47.86691       N    1')

library(ggmap)

myMap <- get_map(location=colMeans(d[, c('Lon', 'Lat')]), source="stamen", 
                 maptype="toner", crop=FALSE, zoom=16)
ggmap(myMap) + geom_point(aes(x = Lon, y = Lat), data=d)

enter image description here