How to fit a smooth curve to my data in R?

前端 未结 8 1901
无人共我
无人共我 2020-11-29 15:59

I\'m trying to draw a smooth curve in R. I have the following simple toy data:

> x
 [1]  1  2  3  4  5  6  7  8  9 10
> y
 [1]  2  4  6  8         


        
8条回答
  •  旧巷少年郎
    2020-11-29 16:47

    In ggplot2 you can do smooths in a number of ways, for example:

    library(ggplot2)
    ggplot(mtcars, aes(wt, mpg)) + geom_point() +
      geom_smooth(method = "gam", formula = y ~ poly(x, 2)) 
    ggplot(mtcars, aes(wt, mpg)) + geom_point() +
      geom_smooth(method = "loess", span = 0.3, se = FALSE) 
    

提交回复
热议问题