The following code produces histograms that overlap. How can I modify this code to make the histograms stack on top of each other?
library(tidyverse)
library(ggridges)
iris %>%
pivot_longer(cols = -Species,
names_to = "Param",
values_to = "Value") %>%
ggplot(aes(x = Value, y = Param))+
geom_density_ridges(aes(fill = Species),
stat = "binline",
alpha = 0.5)
I can achieve a desired effect using geom_histogram
and facet_wrap
as shown below, but from aesthetics perspective prefer a solution using ggridges
.
iris %>%
pivot_longer(cols = -Species,
names_to = "Param",
values_to = "Value") %>%
ggplot(aes(x = Value))+
geom_histogram(aes(fill = Species),
position = position_stack(),
alpha = 0.5) +
facet_wrap(~Param,ncol = 1,scales = "free_y")
it sounds trivial, but I tried exchanging
with
in your dplyr code, and it worked.
Is this what you wanted?