# NOT RUN {
## using lat/lon coordinates
set_key("your_api_key")
google_map(data = tram_route) %>%
add_polylines(lat = "shape_pt_lat", lon = "shape_pt_lon")
google_map() %>%
add_polylines(data = melbourne, polyline = "polyline", stroke_weight = 1,
stroke_colour = "SA4_NAME")
## using encoded polyline and various colour / fill options
url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv'
flights <- read.csv(url)
flights$id <- seq_len(nrow(flights))
## encode the routes as polylines
lst <- lapply(unique(flights$id), function(x){
lat = c(flights[flights["id"] == x, c("start_lat")], flights[flights["id"] == x, c("end_lat")])
lon = c(flights[flights["id"] == x, c("start_lon")], flights[flights["id"] == x, c("end_lon")])
data.frame(id = x, polyline = encode_pl(lat = lat, lon = lon))
})
flights <- merge(flights, do.call(rbind, lst), by = "id")
style <- map_styles()$night
google_map(key = map_key, style = style) %>%
add_polylines(data = flights, polyline = "polyline", mouse_over_group = "airport1",
stroke_weight = 1, stroke_opacity = 0.3, stroke_colour = "#ccffff")
# }
Run the code above in your browser using DataLab