Connect 2 points on the map using ggplot

I have the following code for plotting 2 points in ggmap

library(ggmap)
library(ggplot2)

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

Bangalore <- get_map("Bangalore,India", zoom=12)

p <- ggmap(Bangalore)
p + geom_point(data=d, aes(x=lon, y=lat),color="red",size=3)

ggplot(p)

These dots appear as red dots on the map. How can I connect these points?

+4
source share
1 answer

Not necessary for the final one ggplot(p)(maybe you selected a bug at your end) and I would 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

+5
source

All Articles