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

2023-12-12 Thread Rui Barradas
Às 00:36 de 13/12/2023, Robert Baer escreveu: coord_cartesian also seems to work for y, and including the breaks = . How about: df=data.frame(year= c(2012,2015,2018,2022),   score=c(495,493, 495, 474)) ggplot(df, aes(x = year, y = score)) +   geom_point() +   geom_smooth(method

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

2023-12-12 Thread Ebert,Timothy Aaron
y = "PISA score in mathematics") + scale_y_continuous(limits=c(470,500),oob=scales::squish) Regards, Tim -Original Message- From: R-help On Behalf Of varin sacha via R-help Sent: Tuesday, December 12, 2023 4:19 PM To: r-help@r-project.org; Ben Bolker Subject: Re: [R] ggplot2: Get the r

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

2023-12-12 Thread Robert Baer
coord_cartesian also seems to work for y, and including the breaks = .  How about: df=data.frame(year= 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 = y ~ x) +   labs(title =

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

2023-12-12 Thread Ben Bolker
Use scale_x_continuous() and specify your desired breaks On Tue, Dec 12, 2023, 4:19 PM varin sacha wrote: > Dear Ben, > Dear Daniel, > Dear Rui, > Dear Bert, > > Here below my R code. > I really appreciate all your comments. My R code is perfectly working but > there is still something I would

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

2023-12-12 Thread varin sacha via R-help
Dear Ben, Dear Daniel, Dear Rui, Dear Bert, Here below my R code. I really appreciate all your comments. My R code is perfectly working but there is still something I would like to improve. The X-axis is showing   2012.5 ;   2015.0   ;   2017.5   ;  2020.0 I would like to see on X-axis only the

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

2023-12-11 Thread Ben Bolker
On 2023-12-11 5:27 p.m., Daniel Nordlund wrote: On 12/10/2023 2:50 PM, Rui Barradas wrote: Às 22:35 de 10/12/2023, varin sacha via R-help escreveu: 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

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

2023-12-11 Thread Daniel Nordlund
On 12/10/2023 2:50 PM, Rui Barradas wrote: Às 22:35 de 10/12/2023, varin sacha via R-help escreveu: 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

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

2023-12-10 Thread Bert Gunter
This can easily be done using predict.lm to get the intervals (confidence or prediction). ?predict.lm contains a plotting example using ?matplot from the graphics package. Here's a somewhat verbose version for your example (first converting Year to numeric, of course): df=data.frame(year=

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

2023-12-10 Thread Rui Barradas
Às 22:35 de 10/12/2023, varin sacha via R-help escreveu: 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,

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

2023-12-10 Thread varin sacha via R-help
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. #