Skip to content

geom_path should support intermediate arrows #2280

Closed

Description

geom_path() supports the arrow argument, but this only adds an arrow to the end of the path.

library(ggplot2)
set.seed(660124238)
plotDF <- data.frame(x = runif(6), y = runif(6))
ggplot(plotDF, aes(x, y)) + 
  geom_path(arrow = arrow())

If this geom supported intermediate arrows, it would be trivial to use ggplot2 to create connected scatterplots. It's currently possible--but cumbersome--to create connected scatterplots with geom_segment().

ggplot(plotDF, aes(x, y)) + 
  geom_segment(aes(xend = dplyr::lead(x), yend = dplyr::lead(y)),
               arrow = arrow())

If folks agree that this change is worth making, I'm not sure if it would be cleaner to implement this by passing a vector of arrow objects to the geom's arrow argument, or through changes to the arrow function.

Activity

  1. hadley commented on Oct 30, 2017

    @hadley
    Member

    This out of scope for ggplot2 since it would require a lot of work - it would be better to implement in an extension package instead.

  2. mikejacktzen commented on Dec 13, 2017

    @mikejacktzen

    I came across this same feature wish while making network plots

    https://mikejacktzen.wordpress.com/portfolio/be-a-bigballr-in-rstats/

    I guess an intermediate solution would be if geom_path or geom_segment() or geom_curve() could return a set of discretized coordinates that was used to plot the curves

    curve_id, x_1, y_1
    

    that way the user can post process outside of ggplot2 to figure out which point in the set of coordinates they can use to add another geom layer

    In this case, pluck out the mid point and then overlay a triangle or something

    I dug around and see that geom_curve() uses grid::curveGrob()

    but i can't quite figure out how curveGrob() returns the coordinate values

    The big picture would be, once the curveGrob() coordinates are identified, the ggplot2 user could extract that from

    p = ggplot() + geom_curve()
    
    str(p)
    
    p$geom_curve$coordinates
    
    # whose values would be a data.frame looking like 
    # c(curve_id, x_1, y_1)
    

    Then use it like

    dat_midpoints = (p$geom_curve$coordinates)[c(1,3,5),]
    p2 = ggplot() + geom_curve(...,arrow=NULL) + geom_segment(data=dat_midpoints ,arrow=arrow())
    
    
  3. locked as resolved and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions