MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Analyzing Survey Data in R

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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(___))
Edit dan Jalankan Kode