plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Add support for ggridges

Open AdroMine opened this issue 7 months ago • 4 comments

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

AdroMine avatar Nov 05 '23 13:11 AdroMine

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

cpsievert avatar Nov 10 '23 16:11 cpsievert

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)

cpsievert avatar Nov 10 '23 16:11 cpsievert

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?

AdroMine avatar Nov 10 '23 18:11 AdroMine

@cpsievert, when do you anticipate this will be merged to main?

ashirwad avatar Jan 10 '24 18:01 ashirwad

Awesome work, thank you!

cpsievert avatar May 08 '24 19:05 cpsievert