Search code examples
rgoogle-mapsmapsbokeh

How to add lines segments to a google map


How can I add lines segments between two points in a gmap using the rbokeh package.

For example, the code below draw the points but doesn't add the segments.

library(rbokeh)
pts <- data.frame(lat=c(40.73, 40.72), lng=-74)
gmap(lat = 40.73306, lng = -73.97351, zoom = 14, width = 680, height = 600) %>%
         ly_points(x=lng, y=lat, data = pts, col = "red")  %>%
         ly_segments(x0=-74, x1=-74, y0=40.72, y1=40.73, color="red", width=2)

Solution

  • You have to use ly_lines() to add lines to your plot. Add ly_lines(x=lng, y=lat, data=pts) %>% befor your ly_points.