Итак, это мое самое близкое приближение к тому, что я получил от вашего вопроса:
# Dummy data
df <- data.frame(
y = c(rnorm(100, 4), rnorm(100, 12)),
x = rep(c(1, 2), each = 100)
)
ggplot(df, aes(x, y, group = x)) +
# To fill gap between 0 and actual data
stat_summary(geom = "rect",
fun.ymin = function(x){0},
fun.ymax = min,
aes(xmin = x - 0.4, xmax = x + 0.4, fill = 0)) +
# To make the density part
stat_ydensity(aes(fill = stat(density),
xmin = x - 0.4, xmax = x + 0.4,
# Nudge y by a bit depending on the spread of your data
ymin = stat(y) - 0.01, ymax = stat(y) + 0.01),
geom = "rect", trim = FALSE)
![enter image description here](https://i.stack.imgur.com/bVnaF.png)
Соответствует ли это требованиям?