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

allow slab subgroups to have different widths #150

Open
japhir opened this issue Sep 9, 2022 · 3 comments
Open

allow slab subgroups to have different widths #150

japhir opened this issue Sep 9, 2022 · 3 comments

Comments

@japhir
Copy link

japhir commented Sep 9, 2022

I have some data where I average many y-values together over a large range of x-values, and I want to be able to draw a gradient that spans the range of x-values.

As a workaround I have been able to just set a very large width and then post-process the gradients in Inkscape.

I have also tried passing the variable as a width aesthetic, but this still remained the same for each bin.

Here's an image illustrating the desired outcome after specifying either the width or an xmin and xmax as aesthetics:
ggdist_gradient

@mjskay
Copy link
Owner

mjskay commented Sep 9, 2022

Hmm yeah, this doesn't really work at the moment because slabinterval enforces each subgroup to have the same width. E.g. this is the closest I could get (notice only one group correctly covers the data points along the x axis):

set.seed(1234)

data.frame(
  g = c("a","b"), 
  var1 = rnorm(1000, 1:2), 
  var2 = rnorm(1000)
) |>
  ggplot(aes(
    x = ave(var1, g, FUN = min),
    y = var2, 
    fill = g,
    width = ave(var1, g, FUN = \(x) diff(range(x)))
  )) +
  stat_gradientinterval(scale = 1, side = "right", justification = 0, fill_type = "gradient", color = NA)  + 
  geom_point(aes(x = var1), pch = 21, alpha = 0.5)

image

I'm not entirely sure it would be straightforward to relax that constraint on equal widths, as it is used to ensure dodging works properly (unless I'm misremembering), but I can look into it... it's possible I can allow it to be overridden if it's set manually.

@japhir
Copy link
Author

japhir commented Sep 10, 2022

I'm happy you were able to parse my vague issue into a reprex that precisely reflects my intended outcome, thanks for the effort. For now resolving this does not have priority for me, I'll just tweak the figure manually if needed. But let's leave the issue open to see if there's further interest---or otherwise close it and explain that it may be beyond the scope of the package for now ;-).

@mjskay
Copy link
Owner

mjskay commented Sep 11, 2022

:)

I don't mind leaving it open; I might take a stab at fixing it eventually or maybe someone will wander along who's interested.

@mjskay mjskay changed the title [feature request] make it possible to stretch the ggdist::stat_gradientinterval also to xmin and xmax or ymin and ymax allow slab subgroups to have different widths Oct 16, 2022
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

No branches or pull requests

2 participants