Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6649.

This PR adds additional lines to the key glyphs when the outline.type is not full.
Arguably draw_key_timeseries() could also be made to support the fill aesthetic under all circumstances, but that is not enforced in this PR.

Demonstrations, notice the legend keys:

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

ggplot(economics, aes(date)) +
  geom_area(
    aes(y = unemploy, fill = "Unemployment"),
    alpha = 0.5, colour = "black", outline.type = "upper"
  ) +
  geom_area(
    aes(y = pce, fill = "PCE"),
    alpha = 0.5, colour = "black", outline.type = "both"
  ) +
  geom_area(
    aes(y = pop / 30, fill = "Population"),
    alpha = 0.5, colour = "black", outline.type = "lower"
  ) +
  theme(
    legend.key.spacing.y = unit(5.5, "pt")
  )

And for draw_key_timeseries():

ggplot(economics, aes(date)) +
  geom_area(
    aes(y = unemploy, fill = "Unemployment"),
    alpha = 0.5, colour = "black", outline.type = "upper",
    key_glyph = draw_key_timeseries
  ) +
  geom_area(
    aes(y = pce, fill = "PCE"),
    alpha = 0.5, colour = "black", outline.type = "both",
    key_glyph = draw_key_timeseries
  ) +
  geom_area(
    aes(y = pop / 30, fill = "Population"),
    alpha = 0.5, colour = "black", outline.type = "lower",
    key_glyph = draw_key_timeseries
  ) +
  theme(
    legend.key.spacing.y = unit(5.5, "pt")
  )

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

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.

Better key_glyphs for geom_ribbon() and friends
1 participant