2017-10-16 156 views
0

我在R中绘制纬度和经度(共300个),但我的代码仅在地图上显示单个点。任何人都可以请告诉我如何可视化地图上的所有点? GPS plots 我的代码在下面提到;在R中的地图上绘制每个坐标

library("ggmap") 
library(maptools) 
library(maps) 


visit.x <- Nlongs 
visit.y <- Nlats 

mp <- NULL 
mapWorld <- borders("world", colour="gray50", fill="gray50") 
# create a layer of borders 
mp <- ggplot() + mapWorld 
#Now Layer the cities on top 
    mp <- mp+ geom_point(aes(x=visit.x, y=visit.y) ,color="blue", size=3) 
    mp 



> Nlongs 
    [1] 5.010786 5.010823 5.010862 5.010823 5.010873 5.010872 5.010873 
    5.010823 5.010872 

    > Nlats 
    [1] 47.29396 47.29397 47.29398 47.29397 47.29396 47.29396 47.29396 
    47.29397 47.29393 
+0

检查'll.visited'的输出,你只有1对多头和拉特的。 “visited”向量包含300个访问过的地方而不是1个?此外,代码应该是'visit.y < - ll.visited $ lat','visit.x < - ll.visited $ lon'。 'Nlongs'和'Nlats'从哪里来?它没有在你的例子中定义。 – Djork

+0

谢谢你的回复。是的,你是对的,但它仍然给我一点阴谋。 – sara

回答

0

这里是正确的实施。您需要提供/阅读300个访问城市的名称列表,以visited载体。在这里,我提供3

visited <- c("Dijon", "Cambridge", "Los Angeles") 
ll.visited <- geocode(visited) 
ll.visited 


mp <- NULL 
mapWorld <- borders("world", colour="gray50", fill="gray50") 

# provide ll.visited data to ggplot 
mp <- ggplot(ll.visited) + mapWorld 

# assign x and y to correspond to lon and lat of ll.visited 
mp <- mp + geom_point(aes(x=lon, y=lat), color="blue", size=3) 
mp 

enter image description here