I'd like to produce a plot that shows a time series followed by a set of forecast distributions, each represented as a violin plot. The example code below creates and plots a time series (as a line plot) and two violin plots separately.
set.seed(12345)
x <- data.frame(time=1:50, dat=rnorm(50))
y1 <- rnorm(500)
y2 <- rnorm(500, sd=5)
y <- data.frame(time=as.factor(c(rep(51,500),rep(52,500))), dat=c(y1,y2))
ggplot(x, aes(x=time, y=dat)) +
geom_line()
ggplot(y, aes(x=time, y=dat)) +
geom_violin()
How can I combine these into a single chart with a line plot from time points 1 to 50 (along the x axis) followed by the two violin plots at time points 51 and 52, respectively?


ggplot(mapping = aes(x=as.factor(time), y=dat)) + geom_line(data = x, aes(group = 1)) + geom_violin(data = y)?