summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
library(ggplot2)
# Vẽ biểu đồ scatter plot
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "blue", size = 3) +
geom_smooth(method = "lm", color = "red", linetype = "dashed") +
labs(title = "Mối quan hệ giữa mpg và trọng lượng xe",
x = "Trọng lượng xe (wt)",
y = "Mức tiêu hao nhiên liệu (mpg)")
## `geom_smooth()` using formula = 'y ~ x'
