# 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))
# The default behavior of geom_smooth()
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(method = "auto")
# Use span to control the "wiggliness" of the default loess smoother.
# The span is the fraction of points used to fit each local regression:
# small numbers make a wigglier curve, larger numbers make a smoother curve.
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(method = "loess", span = 0.3)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(method = lm, formula = y ~ splines::bs(x, 3), se = FALSE)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
stat_poly_line(method = lm, formula = x ~ splines::bs(y, 3), se = FALSE)
# 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(method = "auto", span = 0.8) +
facet_wrap(~drv)
# }
Run the code above in your browser using DataLab