掌握点的地图,使用ggmap和GGPLOT2(Getting a map with points,

2019-07-20 11:46发布

我想用它点(和其他geom_ *层)的地图。 我得到的地图,但不是点我得到的是一个警告:

Message d'avis :
Removed 3 rows containing missing values (geom_point).

这是一个可重复的为例:

library(ggmap)
library(ggplot2)

d <- data.frame(lat=c(50.659631, 50.607213, 50.608129),
                lon=c(3.09319, 3.011473, 3.031529))

Lille <- get_map("Lille,France", zoom=12)

p <- ggmap(Lille)
p <- p + geom_point(data=d, aes(lat, lon))
p

展望输出

ggplot_build(p)

我看到NAS进行x和y的一层,但我不知道为什么,从d的数据不被考虑。

当使用ggplot()而不是ggmap(),我得到的点。 但我需要的地图太:)

所以,我怎么能得到超过它 地图吗?

谢谢

Answer 1:

在您的经度和纬度值geom_point()是在错误的顺序。 lon应尽可能x值和lat作为y值。

 p + geom_point(data=d, aes(x=lon, y=lat),size=5)


Answer 2:

看来你只是倒经度和纬度:

p <- ggmap(Lille)
p + geom_point(data=d, aes(x=lon, y=lat), color="red", size=30, alpha=0.5)



文章来源: Getting a map with points, using ggmap and ggplot2
标签: r ggplot2 ggmap