I have cyclic data that I am trying to plot a mean overlayed on a standard deviation band. Using geom_ribbon() has the same issue as geom_line() as it connects the nearest x values, not the order of the data. Is there a way to fill data between two paths, not lines? Here is an example. As the resulting figure shows the standard deviation lines are connected by nearest x whereas the mean (y) is the correct data path from the geom_path().
library(tidyverse)
DF <- tibble(
Order = seq(1,20),
x = c(seq(0,18,2), seq(19, 1, -2)),
y = sin(4.5*(Order-1)*pi/180),
sd1 = y + 1,
sd2 = y - 1
)
p <- ggplot(DF, aes(x=x, y=y)) +
geom_ribbon(aes(ymin = sd1, ymax = sd2), fill = 'lightblue', alpha = 0.2) +
geom_path()
ggsave('plot.png', p)