Connecting 2 points in a map using ggplot

后端 未结 1 1022
一生所求
一生所求 2021-01-13 22:39

I have the following code to plot 2 points in ggmap

library(ggmap)
library(ggplot2)

d <- data.frame(lat=c(12.97131,12.98692),
        lon=c(77.5121,77.68         


        
相关标签:
1条回答
  • 2021-01-13 23:11

    No need for the final ggplot(p) (that's probably throwing an error on your end) and I'd use geom_path:

    p <- ggmap(Bangalore)
    p <- p + geom_point(data=d, aes(x=lon, y=lat),color="red",size=3)
    p + geom_path(data=d, aes(x=lon, y=lat), color="black", size=1)
    ## or....
    p + geom_line(data=d, aes(x=lon, y=lat), color="black", size=1)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题