stat = "density" and jittered_points do not work together
akarlinsky opened this issue · 3 comments
From the vignette, it states that in order to compute the density separately for each group, we can use stat="density" and height=..density.. .
Unfortunately, It seems that this doesn't work with jittered points, as you can see here:
Jittered points work as expected, but the densities look too much alike as the density is estimated for all X:
library(tidyverse)
library(ggridges)
iris %>%
mutate(group_pl = cut_number(Petal.Length, n=5)) %>%
ggplot(aes(x = Sepal.Length, y = Species)) +
geom_density_ridges(jittered_points = TRUE,
alpha = 0.8,
scale = 1,
rel_min_height = 0.01,
aes(point_fill = group_pl,
point_color = group_pl,
group = Species)) +
theme_ridges() +
theme(legend.position = "none")
#> Picking joint bandwidth of 0.181
Using stat="density" and height = ..density.. gives the expected densities, but points are no longer available - parameter us "unknown".
iris %>%
mutate(group_pl = cut_number(Petal.Length, n=5)) %>%
ggplot(aes(x = Sepal.Length, y = Species)) +
geom_density_ridges(jittered_points = TRUE,
alpha = 0.8,
scale = 1,
rel_min_height = 0.01,
aes(point_fill = group_pl,
point_color = group_pl,
group = Species,
height = ..density..),
stat = "density") +
theme_ridges()
#> Warning: Ignoring unknown parameters: jittered_points
Created on 2019-09-17 by the reprex package (v0.3.0)
See #42. stat_density()
does not have the same parameter options that stat_density_ridges()
has. I'm happy to accept a PR that improves the documentation.
I thought adding an option to geom_density_ridges such as "bygroup" which flags if the bandwidth estimation should be by group or on the whole range of x values.
Unfortunately, I'm not skilled enough in R programming to achieve this.
Please file an issue with this specific request then. I'm going to close this one.