我在R中绘制纬度和经度(总共300个)但是我的代码只在地图上显示一个点。任何人都可以告诉我如何可视化地图上的所有点? 我的代码如下所述;
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 :(得分: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