简体   繁体   中英

Plotting every coordinate on a Map in R

I am plotting latitudes and longitudes (300 in total) in R. But my code is only showing a single point on a map. Can anyone please tell me how to visualize all the points on a map ? GPS图 My code is mentioned below;

 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

Here is the correct implentation. You will need to provide/read in a list of names of the 300 visited cities to the visited vector. Here I provide 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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM