I'm trying to produce a faceted ridgeplot, where some ridges are empty. The code below produces an example.
library(ggridges)
library(tidyverse)
df <- tibble(x = rnorm(1000, 1, 1),
id = c(rep(1, 600), rep(2, 400)),
year = c(rep(2000:2005, each = 100), rep(2000:2003, each = 100)))
df %>%
ggplot(aes(x = x, y = as.factor(year))) +
geom_density_ridges2() +
facet_grid(.~id) +
geom_vline(xintercept = 0)
The vertical line here stretches through the years in facet 2 for which there is no data. How can I prevent this and stop it after 2003?