I am trying to reflect estimated uncertainty in my geom_density() plots of my coefficient (yes that is a lot of random effect coefficients) by adding in a grey SE line.
But I am struggling to connect or link the grey shaded area to my geom_density plot in ggplot in R. The location of the grey uncertainty interval is wrong.
I am also aware of this answer (Add shaded standard error curves to geom_density in ggplot2) but it does not work for me. I have tried changing where I declare my ymin and ymax variables and if I append to the variable name the dataset name or not. I have spent a full day on this problem now...
DF <- data.frame(x=rep(1,576))
DF$V <- rnorm(576,mean=2,sd=0.2)
DF$V_se <- rnorm(576,mean=0.2,sd=0.01)
ggplot(data = DF, aes(x = V, ymin = V - (2*V_se),ymax = V + (2*V_se))) +
geom_ribbon(alpha=0.1, colour = NA)+
geom_density()
The grey line prints in a downward sloping diagonal. Instead I would like the grey ribbon to print and follow along the density curve, to show the degree of uncertainty along the curve. (And I can see that this is a bit odd perhaps give that this is a kernel approximation of the data in the first pace.) See image link please
Thank you!