plotly.R
plotly.R copied to clipboard
Add support for ggridges
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]")
))
ggplotly(p)
(p2 <- ggplot(iris, aes(x = Sepal.Length, y = Species)) +
ggridges::geom_density_ridges(fill = 'midnightblue', alpha = 0.6))
ggplotly(p2)
Wow, incredible work, thank you! I'm going to add some nit-picky comments, but overall this is looking great
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)
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()
'sopacityDim
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?
@cpsievert, when do you anticipate this will be merged to main?
Awesome work, thank you!