Plot coordinates on map

前端 未结 4 1477
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 12:17

I am trying to plot my coordinates using R. I have tried already to follow different post (R: Plot grouped coordinates on world map ; Plotting coordinates of multiple points

4条回答
  •  天命终不由人
    2020-12-07 13:10

    An other alternative, is the plotGoogleMaps package which allows to plot in a navigator, allowing to zoom in and out etc. You can then make a screenshot of your picture to save it (though remember google maps are legally supposed to be used for the internet).

     library("plotGoogleMaps")
     lat <- c(-38.31, -35.50) #define our map's ylim
     lon <- c(40.96,37.50) #define our map's xlim
    
     # make your coordinates a data frame 
     coords <- as.data.frame(cbind(lon=lon,lat=lat))
    
     # make it a spatial object by defining its coordinates in a reference system
     coordinates(coords) <- ~lat+lon 
    
     # you also need a reference system, the following should be a fine default
     proj4string(coords) <- CRS("+init=epsg:4326")
     # Note: it is a short for: 
     CRS("+init=epsg:4326")
     > CRS arguments:
     >  +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
    
     # then just plot
     a <- plotGoogleMaps(coords)
     # here `a <-` avoids that you get flooded by the html version of what you plot 
    

    And you get :

提交回复
热议问题