在R中绘制地图上的每个坐标
Plotting every coordinate on a Map in R
我在 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
下面是正确的实现。您需要将 provide/read 中的 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
我在 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
下面是正确的实现。您需要将 provide/read 中的 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