0
votes

I have a data-frame df in long format (several observations for each year). I want to plot the average of the variable length for each year across years with confidence intervals. I use this code:

ggplot(df[df$year>2004,],aes(x=year, y=length)) +
    stat_summary(fun.data = "mean_cl_boot", geom = "smooth") +
    xlab("") + ylab("Report Length") +
    scale_x_continuous(breaks = seq(2005, max(df$year), by = 2))

The last time I ran this code it gave me the exact graph I want: What I want, but this time the confidence interval does not show up: What I get I did not change the code, but I did update all the packages and now I can't get the confidence intervals.

1
I think you'll get them adding se = TRUE. As far as I know this the default, so I'm not sure why it doesn't show up without that. - aosmith
Is data the same? - pogibas
@ aosmith Thank you, it did solve the problem! @ PoGibas Yes, the data are the same. However, the data are not exactly the same between the plots I posted here because the 1st plot was done when I manipulated the length variable (hence difference in y axis), but it was the only plot i had left from the last successful run with CIs. - Michael

1 Answers

3
votes

Adding se = TRUE, as suggested by @aosmith, solved the problem. The code now looks like this:

ggplot(df[df$year>2004,],aes(x=year, y=length)) +
    stat_summary(fun.data = "mean_cl_boot", geom = "smooth", se = TRUE) +
    xlab("") + ylab("Report Length") +
    scale_x_continuous(breaks = seq(2005, max(df$year), by = 2))

It remains unclear why it worked earlier without specifying se = TRUE and does not work now.