Skip to content

geom_ribbon: aesthetics can not vary with a ribbon #4690

Closed
@markjrieke

Description

@markjrieke

Hi! I ran across the error in the title when mapping alpha to an aesthetic in geom_ribbon. ggplot2 is a mature package, so I suspect there are well-founded reasons this isn't supported, but on the off-chance, is this something that can be considered in the future?

In my use case, I was mapping confidence interval around an estimate to geom_ribbon, and wanted to have it "fade out" as it projected beyond the current date. Here's a toy reprex with the error:

library(tidyverse)

pi <- 3.1415926

tibble(x = seq(0, 2 * pi, length.out = 100)) %>%
  mutate(estimate = sin(x),
         ci_hi = estimate + 0.1,
         ci_lo = estimate - 0.1,
         
         # decrease alpha from pi -> 2*pi
         alpha = if_else(x >= pi, 0.25 * (1 - (x - pi)/pi), 0.25)) %>%
  ggplot(aes(x = x,
             y = estimate,
             ymin = ci_lo,
             ymax = ci_hi)) + 
  geom_line() +
  geom_ribbon(aes(alpha = alpha))
#> Error: Aesthetics can not vary with a ribbon

Created on 2021-12-07 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions