首页 文章

错误:提供给连续刻度的离散值

提问于
浏览
3

我正在使用ggmap来处理马达加斯加的 Map

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

并从x y lat / lon网格绘制该 Map 上的点

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

来自这样的数据

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

但我得到这个错误:

Error: Discrete value supplied to continuous scale

我该怎么办?

1 回答

  • 4

    您将字符串 "Lon""Lat" 传递给 xy 而不是传递 LonLat 本身 . 拿出报价,你应该没事 .

    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

相关问题