Line of best fit
What's the relationship between height and weight across all ages?
In this exercise, we will add the line of best fit to a bubble plot and see that the trend isn't very linear. We can create a polynomial curve by adding the argument formula = y ~ poly(x, d)
to geom_smooth()
where d
is the degree of the polynomial. For example, d
of 2 adds a quadratic and a d
of 3 adds a cubic.
This exercise is part of the course
Analyzing Survey Data in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Bubble plot with linear of best fit
ggplot(data = NHANESraw, mapping = aes(x = ___, y = ___, size = ___)) +
geom_point(alpha = 0.1) +
guides(size = "none") +
geom____(method = ___, se = FALSE, mapping = aes(___))