Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_ribbon: aesthetics can not vary with a ribbon #4690

Open
markjrieke opened this issue Dec 7, 2021 · 4 comments · May be fixed by #5699
Open

geom_ribbon: aesthetics can not vary with a ribbon #4690

markjrieke opened this issue Dec 7, 2021 · 4 comments · May be fixed by #5699
Labels
feature a feature request or enhancement

Comments

@markjrieke
Copy link

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)

@clauswilke
Copy link
Member

Yes, this has not been possible due to limitations with the R graphics devices. With the latest improvements, this may now be possible, though probably not trivial. It's a reasonable request though.

@clauswilke clauswilke added the feature a feature request or enhancement label Dec 7, 2021
@clauswilke
Copy link
Member

Related: #3997

@thomasp85
Copy link
Member

The way the new grid features have been implemented means that it is non-trivial to map aesthetics to e.g. gradients so it is something that will take quite some work to get right... but hopefully someday

@clauswilke
Copy link
Member

A related feature has been implemented in ggdist:
https://mjskay.github.io/ggdist/articles/slabinterval.html#gradient-plots-1

The relevant code is here:
https://github.com/mjskay/ggdist/blob/d660a34bb58aaca44c0c12ab35b472ca222ee9fe/R/geom_slabinterval.R#L792-L818

It doesn't seem too complicated, at least for gradients in one dimension. The problem for the feature requested here is that it will require a 2d gradient (alpha value depends on x and y position), but I believe that's in principle possible also.

@teunbrand teunbrand linked a pull request Feb 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants