Plot coordinates on map

前端 未结 4 1492
被撕碎了的回忆
被撕碎了的回忆 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 12:58

    As an alternative to RgoogleMaps, you can also use the combination ggplot2 with ggmap.

    With this code:

    # loading the required packages
    library(ggplot2)
    library(ggmap)
    
    # creating a sample data.frame with your lat/lon points
    lon <- c(-38.31,-35.5)
    lat <- c(40.96, 37.5)
    df <- as.data.frame(cbind(lon,lat))
    
    # getting the map
    mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
                          maptype = "satellite", scale = 2)
    
    # plotting the map with some points on it
    ggmap(mapgilbert) +
      geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
      guides(fill=FALSE, alpha=FALSE, size=FALSE)
    

    you get this result: enter image description here

提交回复
热议问题