Example Needed: Using arrow() with ggplot2

后端 未结 1 514
悲哀的现实
悲哀的现实 2021-02-20 07:04

I\'d like to create a geom_path() that has arrows pointing towards the next location in the path.

I can get the path to plot, without issue, for example:



        
1条回答
  •  时光说笑
    2021-02-20 07:28

    geom_segment has an arrow argument. Here's a short example:

    library(grid) # needed for arrow function
    
    p <- ggplot(df, aes(x=x, y=y)) +
         geom_point() +
         geom_segment(aes(xend=c(tail(x, n=-1), NA), yend=c(tail(y, n=-1), NA)),
                      arrow=arrow(length=unit(0.3,"cm")))
    

    library(grid) is needed for arrow() function, see here.

    0 讨论(0)
提交回复
热议问题