Open mir-cat opened 6 years ago
I would consider a pull request, but it's low on my priority list. It's basically a bunch of copy and paste and replace x by y and vice versa. I wish ggplot2 had a better mechanism of remapping coordinates in stats. Have you tried coord_flip()
?
I do know about coord_flip
but the main issue is integration with other geoms. Right now I am able to combine a joyplot and a sort of 'rug plot' as such:
However, I also want to be able to combine it with a boxplot instead of the rugplot. geom_boxplot
currently only accepts continuous variable on the y
and discrete variables on the x
. I haven'd found a way, even with coord_flip
, to draw these two geoms together. Hence the desire for a geom that natively is discrete x
, continuous y
.
If all it is is taking geom_density_ridges
is swapping x
s with y
s and heights
with widths
that seems like something I can take a stab at.
No, the problem is there also needs to be a horizontal stat_density_ridges
. And the real issue then is code maintenance, how do we make sure the two stats don't diverge over time. That's why I'm hesitant to go down that route. It leads to a lot of duplicated code.
The ggstance package provides horizontal boxplots. Maybe that can be used to solve your specific issue?
the horizontal boxplots in ggstance
do solve my issue:
I had to write a few custom positions to nudge the boxplots, but that was pretty easy to do. Working on this has really informed me about the difficulty of rotating a geom :P
@mir-cat Any chance you can share your custom code for nudging the boxplots?
Hey guys, thank you for ggridges - we love it! I am having a similar question.
I have this geom_density_ridges
plot:
When I use geom_density_ridges + coord_flip
the densities somehow feel flipped. This is because left-to-right no longer corresponds with low-to-high.
How to get the coord_flipped plot mirrorred on the y axis?
So that left-to-right corresponds with low-to-high again?
Requested feedback from ggplot2 folks as well: https://github.com/tidyverse/ggplot2/issues/4301#issuecomment-1208109507
why dont you reverse the scale ?
library(ggplot2)
library(ggridges)
library(patchwork)
a <- ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges() +
theme_ridges()
a2 <- ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges() +
theme_ridges()+
scale_x_reverse()
b <- a +
coord_flip()
c <- b +
scale_x_reverse()
(a + a2) /
(b + c)
#> Picking joint bandwidth of 0.181
#> Picking joint bandwidth of 0.181
#> Picking joint bandwidth of 0.181
#> Picking joint bandwidth of 0.181
Created on 2022-08-08 by the reprex package (v2.0.1)
Dear Samer,
thank you for very much for helping out! Your solution indeed enables reading the scale from left to right. But it also makes the values increase from top to bottom, which is counterintuitive. Mirroring on the Y axis would give left to right while increasing from bottom to top. But how to do that ... I think there is no solution currently ..
just trying to help no problme it can be helpful to show me a mock what you are looking to have as a result. with bi-direction geoms ( not yet supported by ggridges) we do not need coord_flip anymore you can just control your y and x as you see fit you can make the density the other way around or even reverse the y discrete axis but please let me know what plot you want to achieve best wishes
I saw that there is already a vertical ridgeline geom. I was hoping that one for vertical density ridgelines could be provided as well :)