teunbrand / ggarrow

ggplot2 extension: more options for drawing arrows
https://teunbrand.github.io/ggarrow/
Other
51 stars 0 forks source link

Feature request: support for linetype aesthetic #5

Closed rossellhayes closed 6 months ago

rossellhayes commented 7 months ago

Not sure if this package is under active development, but I've found it really useful so figured I would try opening an issue.

I've been using geom_arrow_segment() in a project and one limitation I've faced is not being able to set a linetype aesthetic. As a workaround, I've been plotting a geom_segment() with the desired linetype in one layer and geom_arrow_segment() with a significantly shortened length in a second layer. This works reasonably well, but it would be great if geom_arrow_segment() could have native support for the linetype aesthetic.

I completely understand if this package isn't a priority (especially given all your recent work on ggplot2), so feel free to disregard if that's the case. Thank you for all the work you've put into this package already, it's been a great help to me.

teunbrand commented 7 months ago

Hi there, thanks for the idea! The reason linetypes aren't supported is because the 'line' is actually a polygon that looks like a line. This makes it easier to support things like variable widths and some of the 'minimal' arrow heads and fins. However, this makes it difficult to implement a linetype, as I'd have to manually divide the polygon into many smaller pieces of polygon. I also have no idea how a linetype should behave under variable widths, as the gaps are usually scaled to the linewidth.

What I perhaps could do is to have linewidth = 0 mean to only draw the arrowheads, so you wouldn't have to shorten the length of a segment manually.

teunbrand commented 6 months ago

Alright linetypes are implemented now. They come with the limitation that they don't support variable linewidths.

library(ggarrow)
#> Loading required package: ggplot2

ggplot(whirlpool(5), aes(x, y, linetype = group)) +
  geom_arrow()

Created on 2024-02-24 with reprex v2.1.0

rossellhayes commented 3 months ago

Thank you, this feature is much appreciated! Great work on this package