Skip to content

Supporting arrows with add_segments in plot_geo #1115

Open
@dfrail24

Description

@dfrail24

I like how the line is showing as curved when using add_segments in plot_geo.
However, using plot_geo, it is difficult to show the movement/direction.
Would it be possible to draw curved arrows instead of curved lines?
I tried adding triangular markers at the end of the line, but this looks ugly since triangles are not oriented correctly:
image

I was hoping we could get something like this except with curved arrows:
image

Here is the code I used to generate the first plot:

library(plotly)
library(dplyr)

flights <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
flights$id <- seq_len(nrow(flights))

geo <- list(
  scope = 'world',
  projection = list(type = 'equirectangular'),  #equirectangular, natural earth, orthographic, kavrayskiy7, miller
  showland = TRUE,
  showcountries = TRUE,
  landcolor = toRGB("gray95"),
  countrycolor = toRGB("gray80")
)

p <- plot_geo(
  locationmode = 'USA') %>%
  layout(geo = geo) %>%
  add_segments(
    data = flights, 
    x = ~start_lon, xend = ~end_lon,
    y = ~start_lat, yend = ~end_lat,
    alpha = 0.3,
    color = ~airport2,
    size = I(2.5),
    hoverinfo = "none"
  ) %>%
  add_markers(
    # data = my_segments %>% 
    #   filter(Family == fam & Units != 0 & From != To),
    data = flights, 
    x = ~end_lon,
    y = ~end_lat,
    color = ~airport2,
    size = 1,
    marker = list(symbol = 'triangle-up'),
    alpha = 1
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions