66  Curvilinear Plots

Read in data

66.1 Linear

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "lm", formula = y ~ x, se = FALSE)+
    theme_bw()

66.2 Polynomial

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "lm", formula = y ~ poly(x, 2), se = F)+
    theme_bw()

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "lm", formula = y ~ poly(x, 3))+
    theme_bw()

66.3 Loess

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "loess", formula = y ~ x)+
    theme_bw()

66.4 Splines

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "gam", formula = y ~ splines::ns(x, 2))+
    theme_bw()

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "gam", formula = y ~ splines::ns(x, 3))+
    theme_bw()

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "gam", formula = y ~ splines::bs(x, 3))+
    theme_bw()

Code
df_data1 %>% 
    ggplot(aes(x = weight, y = height)) +
    geom_point()+
    geom_smooth(method = "lm", formula = y ~ quantreg::qr(.5))+
    theme_bw()
Warning: Failed to fit group -1.
Caused by error:
! 'qr' is not an exported object from 'namespace:quantreg'