A scatter plot displays the relationship between two continuous variables. In ggplot2, we can build a scatter plot using geom_point()
. Scatterplots can show you visually
plot(mtcars$disp, mtcars$mpg)
plot(mtcars$disp, mtcars$mpg,
main = 'Displacement vs Miles Per Gallon',
xlab = 'Displacement', ylab = 'Miles Per Gallon')
plot(mtcars$disp, mtcars$mpg, pch = 6)
plot(mtcars$disp, mtcars$mpg, pch = nlevels(factor(mtcars$cyl)))
plot(mtcars$disp, mtcars$mpg, pch = unclass(mtcars$cyl))
plot(mtcars$disp, mtcars$mpg, cex = 1.5)
plot(mtcars$disp, mtcars$mpg, pch = 5, col = 'blue', bg = 'red')
plot(mtcars$disp, mtcars$mpg, pch = 24, col = 'red', bg = 'blue')
plot(mtcars$disp, mtcars$mpg, pch = 5, col = factor(mtcars$cyl))
plot(mtcars$disp, mtcars$mpg)
abline(h = 20)
plot(mtcars$disp, mtcars$mpg)
abline(v = 200)
plot(mtcars$disp, mtcars$mpg)
abline(a = 29.59, b = -0.0412)
plot(mtcars$disp, mtcars$mpg)
abline(c(29.59, -0.0412))
plot(mtcars$disp, mtcars$mpg)
model <- lm(mpg ~ disp, data = mtcars)
abline(coef(model))