Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #6594.

Briefly, it uses the length of the first arrow (rather than all arrows) to determine key glyph size.
The key glyph only ever draws the first arrow.

In addition, this PR also provides arrow support for line-ish keys:

  • draw_key_abline
  • draw_key_vline
  • draw_key_timeseries

Reprex from issue:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

segment_df <- data.frame(
  x = c(1, 2, 3),
  y = c(1, 2, 1),
  xend = c(2, 3, 4),
  yend = c(2, 1, 2),
  group = c("A", "B", "C"),
  arrow_length = c(0.1, 0.2, 0.3)
)
ggplot(segment_df) +
  geom_segment(
    aes(x = x, y = y, xend = xend, yend = yend, color = group),
    arrow = arrow(length = unit(segment_df$arrow_length, "inches"), type = "closed", angle = 30),
    linewidth = 1.5
  ) +
  theme_minimal()

Created on 2025-09-08 with reprex v2.1.1

@teunbrand teunbrand added this to the ggplot2 4.0.1 milestone Oct 7, 2025
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 627c416 into tidyverse:main Oct 20, 2025
13 checks passed
@teunbrand teunbrand deleted the legend_key_arrows branch October 20, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple lengths of arrows for geom_segment is not working for 3.5.2.9002

2 participants