# NOT RUN {
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line()
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(formula = x ~ y)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(formula = y ~ poly(x, 3))
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(formula = x ~ poly(y, 3))
# Smooths are automatically fit to each group (defined by categorical
# aesthetics or the group aesthetic) and for each facet.
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point() +
stat_poly_line(se = FALSE)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line() +
facet_wrap(~drv)
# Inspecting the returned data using geom_debug()
if (requireNamespace("gginnards", quietly = TRUE)) {
library(gginnards)
ggplot(mpg, aes(displ, hwy)) +
stat_poly_line(geom = "debug")
ggplot(mpg, aes(displ, hwy)) +
stat_poly_line(geom = "debug", mf.values = TRUE)
ggplot(mpg, aes(displ, hwy)) +
stat_poly_line(geom = "debug", method = lm, mf.values = TRUE)
}
# }
Run the code above in your browser using DataLab