ggplot2 smooth | Examples | Plotly

How to add a smoothed line and fit to plots with stat_smooth and geom_smmoth in ggplot2 and R.

library(plotly) x <- rnorm(100) y <- + .7*x + rnorm(100) f1 <- as.factor(c(rep(“A”,50),rep(“B”,50))) f2 <- as.factor(rep(c(rep(“C”,25),rep(“D”,25)),2)) df <- data.frame(cbind(x,y)) df$f1 <- f1 df$f2 <- f2 ggplot(df,aes(x=x,y=y)) + geom_point() + facet_grid(f1~f2) + stat_smooth(method=“lm”) ggplotly()

Link

Leave a Reply

Your email address will not be published. Required fields are marked *