plotly / plotly/plotly.R

Supporting arrows with add_segments in plot_geo

Open
#1,115 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plotly.js
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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
  )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied R example using plot_geo and add_segments, including the curved flight paths and endpoint markers. Investigate how curved segments are rendered and whether arrow geometry can follow their direction. Done means plot_geo can display curved arrows with correctly oriented arrowheads.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.