Skip to content

Add support for ggridges #2314

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

Merged
merged 5 commits into from
May 8, 2024
Merged

Conversation

AdroMine
Copy link
Contributor

@AdroMine AdroMine commented Nov 5, 2023

Closes #1912

Add support for ggrides package

I took inspiration from the #1087 and have a version that supports most of the ggridges functionality. The test file has all the examples from ggridges introduction vignette

What's working:

  • geom_ridgeline
  • geom_density_ridges (including custom densities (stat = identity), bin shape, custom heights)
  • geom_density_ridges2
  • geom_ridgeline_gradient
  • stat_density_ridges
  • stat_denstity_ridges with gradients
  • ridges with jittered points / raincloud effect, points variations

What's not working:

  • geom_ridgeline_gradient with continuous colours
  • geom_vridgeline

ggridge functions that already working without new code:

  • themes (axis title placement is off)
  • scale_fill_cyclical (custom label names don't work)

Examples:

(p <- ggplot(iris, aes(x = Sepal.Length, y = Species, fill = factor(stat(quantile)))) +
  stat_density_ridges(
    geom = "density_ridges_gradient",
    calc_ecdf = TRUE,
    quantiles = c(0.025, 0.975)
  ) +
  scale_fill_manual(
    name = "Probability", values = c("#FF0000A0", "#A0A0A0A0", "#0000FFA0"),
    labels = c("(0, 0.025]", "(0.025, 0.975]", "(0.975, 1]")
  ))

image

ggplotly(p)

image

(p2 <- ggplot(iris, aes(x = Sepal.Length, y = Species)) + 
  ggridges::geom_density_ridges(fill = 'midnightblue', alpha = 0.6))

image

ggplotly(p2)

image

@cpsievert
Copy link
Collaborator

Wow, incredible work, thank you! I'm going to add some nit-picky comments, but overall this is looking great

@cpsievert
Copy link
Collaborator

cpsievert commented Nov 10, 2023

I wouldn't consider this a blocking issue, and I'm not sure if this is sensible to address here, but just throwing it out there that it'd be awesome if this worked better (more specifically, it seems highlight()'s opacityDim isn't having an effect on the non-highlighted ridgelines?)

p <- ggplot(iris |> highlight_key(~Species), aes(x = Sepal.Length, y = Species)) + 
  geom_density_ridges(rel_min_height = 0.01)

ggplotly(p) |> highlight("plotly_hover", opacityDim = 0.2)

@AdroMine
Copy link
Contributor Author

I wouldn't consider this a blocking issue, and I'm not sure if this is sensible to address here, but just throwing it out there that it'd be awesome if this worked better (more specifically, it seems highlight()'s opacityDim isn't having an effect on the non-highlighted ridgelines?)

p <- ggplot(iris |> highlight_key(~Species), aes(x = Sepal.Length, y = Species)) + 
  geom_density_ridges(rel_min_height = 0.01)

ggplotly(p) |> highlight("plotly_hover", opacityDim = 0.2)

Didn't know about highlight. Any idea what could be affecting it? Or where I could look to debug?

Comment on lines +253 to +258
text = uniq(data[["hovertext"]]),
key = data[["key"]],
customdata = data[["customdata"]],
frame = data[["frame"]],
Copy link
Collaborator

@cpsievert cpsievert Nov 10, 2023

Choose a reason for hiding this comment

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

I think these need be doubled, like you did for x/y (this might be leading to #2314 (comment))

I'd consider doing something like (using with() here can be kinda dangerous since it'll error if any of the columns are missing

positions <- rbind(data, rev(data))
positions$y <- c(data$ymax, rev(data$ymin))

Copy link
Contributor Author

@AdroMine AdroMine Nov 11, 2023

Choose a reason for hiding this comment

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

Found the issue! Within the new to_basics, I was using to_basic.GeomDensity and to_basic.GeomLine which removed the crosstalk set. Attaching them back again similar to how it's done in layers2traces solves the highlight not working.

Before this, the to_basic.GeomLine would preserve the set attribute, but to_basic.GeomDensity would not, so we were getting highlight working only the line part and not density/area part.

I have tested the highlight functionality with different types of ridge plots, with different fills, points, lines within them, and they are all working as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpsievert are there any pending action items on this, or is this good to go now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for letting this slip @AdroMine, looking good, would you mind just adding a NEWS.md item?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpsievert , added a line about adding support for ggridges package.

@ashirwad

This comment was marked as off-topic.

@AdroMine AdroMine force-pushed the ggridges_support branch from 3297f8d to a329f43 Compare May 8, 2024 18:38
@cpsievert
Copy link
Collaborator

Awesome work, thank you!

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.

ggridges not implemented for ggplotly
3 participants