How to fit a quadratic (curved) line through a scatter plot?. Help

Year Price HAS decades
1 1982 40000 8.98 1980-1989
2 1984 50000 34.30 1980-1989
3 1984 45000 11.00 1980-1989
4 1987 1400000 243.00 1980-1989
5 1989 100000 9.40 1980-1989
6 1989 8000000 69.90 1980-1989

cbrf %>% ggplot(aes(x = HAS, y = PRICE)) +

  • geom_jitter() +
    
  • scale_y_log10(labels = scales::dollar_format()) +
    
  • facet_wrap(~ decades, scales = "free_x") +
    
  • geom_smooth(method = "lm", color = "grey", se = FALSE) +
    
  • theme_light()
    

add a formula to geom_smooth, using x and y rather than HAS and PRICE:

geom_smooth(method = "lm", formula = y ~ x + I(x^2), color = "grey", se = FALSE) 

or

geom_smooth(method = "lm", formula = y ~ poly(x, 2), color = "grey", se = FALSE) 

Thank you so much! Have a nice day.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.