Skip to content
Prev 394804 / 398502 Next

geom_smooth

?s 05:17 de 12/08/2023, Thomas Subia via R-help escreveu:
Hello,

Here is a solution. You ,ust access the computed variables, which you 
can with ?ggplot_build.
Then pass them in the data argument.



p <- ggplot(scatter_data,aes(x=x_var,y=y_var)) +
   geom_point()+
   geom_smooth(se=TRUE,fill="blue",color="black",linetype="dashed")+
   theme_cowplot()

# this is a data.frame, relevant columns are x,  ymin and ymax
fit <- ggplot_build(p)$data[[2]]

p +
   geom_line(data = fit, aes(x, ymin), linetype = "dashed", linewidth = 1) +
   geom_line(data = fit, aes(x, ymax), linetype = "dashed", linewidth = 1)


Hope this helps,

Rui Barradas