我正在使用ggmap处理马达加斯加地图
myMap <- get_map(location=k, source="stamen", maptype="toner", crop=FALSE,
zoom=16)
并从x y lat / lon网格绘制该地图上的点
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
我该怎么办?
答案 0 :(得分:4)
您将字符串"Lon"
和"Lat"
传递给x
和y
,而不是自己传递Lon
和Lat
。拿出报价,你应该没事。
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)