I am making a density plot using the R package ggridges
. I want to remove the long tails produced by the geom_density_ridges(...)
function and keep the vertical median lines produced by the stat_density_ridges(...)
function. Is this possible?
library(tidyverse)
library(ggridges)
# Adds median line but has long tails
diamonds %>%
ggplot(aes(x = carat, y = cut)) +
stat_density_ridges(quantile_lines = TRUE,
quantiles = 2,
vline_color = 'red',
alpha = 0.7) +
theme_bw()
#> Picking joint bandwidth of 0.0647
# No median line but removes long tails
diamonds %>%
ggplot(aes(x = carat, y = cut)) +
geom_density_ridges(rel_min_height = 0.01,
alpha = 0.7) +
theme_bw()
#> Picking joint bandwidth of 0.0647
# Adds median line but still has long tails
diamonds %>%
ggplot(aes(x = carat, y = cut)) +
stat_density_ridges(quantile_lines = TRUE,
quantiles = 2,
vline_color = 'red',
alpha = 0.7) +
geom_density_ridges(rel_min_height = 0.01,
alpha = 0) +
theme_bw()
#> Picking joint bandwidth of 0.0647
#> Picking joint bandwidth of 0.0647
Created on 2024-05-21 with reprex v2.1.0