I'm working on a temperature data set over time and I used a density ridges plot to visualize my data by month. On each plot I included the median and the mean by using 2 geom_density_ridges_gradient
function. The reason why I used two geom_density_ridges_gradient
function is because I wanted to distinguish them by two different colors. My issue is that the second layer/function (mean) is plotted on top of the first, causing an overlapping of the blue line (the mean) on others plot.
How can I avoing the overlapping ?
Here's the code below, I used lincoln_weather
dataset from ggridges
as an example
library(ggridges)
library(ggplot2
ggplot(lincoln_weather, aes(x = `Mean Temperature [F]`, y = Month, fill = stat(x))) +
geom_density_ridges_gradient(
alpha = 0.8,
color = "black",
scale = 2,
rel_min_height = 0,
jittered_points = TRUE,
position = position_points_jitter(
width = 0.05,
height = 0
),
point_shape = "|",
point_size = 3,
point_alpha = 1,
quantile_lines = TRUE,
vline_color = c("green"),
quantile_fun = median
) +
geom_density_ridges_gradient(
scale = 2,
rel_min_height = 0,
quantile_lines = TRUE,
vline_color = c("blue"),
fill = NA,
quantile_fun = mean
) +
scale_fill_viridis_c(name = "Temp. [F]", option = "C") +
labs(title = "Temperatures in Lincoln NE in 2016")