- Used to find patterns of scatter plots
- Simple linear regression uses only 1 line with 1 independent variable
2/8/2025
data("Orange")
library(ggplot2)
tree_data <- data.frame(
Age=Orange$age,
Circumference=Orange$circumference
)
data("faithful")
head(Orange)
## Tree age circumference ## 1 1 118 30 ## 2 1 484 58 ## 3 1 664 87 ## 4 1 1004 115 ## 5 1 1231 120 ## 6 1 1372 142
This data looks at the circumference at breast height of a series of Orange trees, and looks at how they grow as days go by.
Orange Tree Age (days) vs. Circumference (millimeters)
Let’s add the linear regression line to the graph
## `geom_smooth()` using formula = 'y ~ x'
Orange Tree Age (days) vs. Circumference (millimeters)
plot(faithful$waiting,faithful$eruptions, main="Old Faithful Eruptions", xlab="Wait Time (in minutes)", ylab="Eruption Length (in minutes") linear_model <- lm(faithful$eruptions ~ faithful$waiting) abline(linear_model, col="forestgreen")
ggplot(data=faithful, mapping=aes(x=waiting,y=eruptions))+ geom_point()+geom_smooth(method="lm",se=FALSE)
## `geom_smooth()` using formula = 'y ~ x'
Newcastle University. (n.d.). Simple Linear Regression. Numeracy, Maths and statistics - academic skills kit. https://www.ncl.ac.uk/webtemplate/ask-assets/external/maths-resources/statistics/regression-and-correlation/simple-linear-regression.html
Datasets from R Library Datasets