[英]Getting a map with points, using ggmap and ggplot2
I want a map with points (and other geom_* layers) on it. 我想要一个带有点(和其他geom_ *层)的地图。 I get the map, but instead of the points all I get is a warning:
我得到了地图,但是我得到的所有点都是警告:
Message d'avis :
Removed 3 rows containing missing values (geom_point).
Here is a reproducible exemple: 这是一个可重现的例子:
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
Looking in the output of 看着输出
ggplot_build(p)
I see a layer with NAs for x and y, but I do not get why the data from d is not considered. 我看到一个带有用于x和y的NA的图层,但我不明白为什么不考虑来自d的数据。
When using ggplot() instead of ggmap(), I do get the points. 当使用ggplot()而不是ggmap()时,我确实得到了积分。 But I do need the map too :)
但我确实也需要地图:)
So, how can I get a map with points over it? 那么,我怎样才能获得带有积分的地图呢?
Thanks 谢谢
It seems you just inverted longitude and latitude : 你似乎只是颠倒了经度和纬度:
p <- ggmap(Lille)
p + geom_point(data=d, aes(x=lon, y=lat), color="red", size=30, alpha=0.5)
Your longitude and latitude values in geom_point()
are in wrong order. geom_point()
中的经度和纬度值的顺序错误。 lon
should be as x
values and lat
as y
values. lon
应该是x
值, lat
应该是y
值。
p + geom_point(data=d, aes(x=lon, y=lat),size=5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.