简体   繁体   中英

ggplot wont show confidence intervals

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: 我想要的是 , but this time the confidence interval does not show up: 我得到什么 I did not change the code, but I did update all the packages and now I can't get the confidence intervals.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM