Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Analyzing Survey Data in R

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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(___))
Code bewerken en uitvoeren