以下代码生成重叠的直方图。如何修改此代码以使直方图堆叠在一起?
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)
我可以使用geom_histogram
和达到预期的效果,facet_wrap
如下所示,但从美学的角度来看,我更喜欢使用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")