Closed joachim-gassen closed 5 years ago
Whenever you map a discrete variable to a color, ggplot2 automatically sets a group. You'll have to override that to get the result you want.
library(ggplot2)
library(ggridges)
#>
#> Attaching package: 'ggridges'
#> The following object is masked from 'package:ggplot2':
#>
#> scale_discrete_manual
set.seed(42)
df <- expand.grid(x = 1:100, y = letters[1:5], z = 1:3)
df$x <- apply(df, 1, function(df) rnorm(1, which(letters == df['y']), as.integer(df['z'])))
df$z <- as.factor(df$z)
ggplot(df, aes(x, y)) +
geom_density_ridges(aes(point_color = z, group = y), jittered_points = TRUE)
#> Picking joint bandwidth of 0.504
Created on 2019-01-16 by the reprex package (v0.2.1)
You live and learn. Thank you!
I just wanted to say that I was looking for ages for a plot similar to Claus's last comment. So first of all: thank you!
Second, I think maybe adding to the vignette that aes(point_color=var) creates separate densities for each level of var if var is not continuous, and that this can be disabled by passing group=y back in aes() - would be extremely helpful.
Thank you for this fabulous package!
I came across something and I am not entirely sure whether it is a bug or a feature: When using
jittered_points = TRUE
andaes(point_colors)
ingeom_density_ridges()
the effect varies dependent on whether the variable assigned topoint_colors
is continuous or discrete.Also, the latter plot contains a legend while the former does not. Thank you for any insights on what is causing/explaining this behavior.