[R] ggplot2: Get the regression line with 95% confidence bands

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sun Dec 10 23:35:31 CET 2023


Dear R-experts,

Here below my R code, as my X-axis is "year", I must be missing one or more steps! I am trying to get the regression line with the 95% confidence bands around the regression line. Any help would be appreciated.

Best,
S.


#############################################
library(ggplot2)
 
df=data.frame(year=factor(c("2012","2015","2018","2022")), score=c(495,493, 495, 474))
 
ggplot(df, aes(x=year, y=score)) + geom_point( ) + geom_smooth(method="lm", formula = score ~ factor(year), data = df) + labs(title="Standard linear regression for France", y="PISA score in mathematics") + ylim(470, 500)
#############################################



More information about the R-help mailing list