[英]Smoothen curve and get its equation in R
I have this code in R :我在 R 中有这个代码:
plot(p,vec, pch = 4, xlab= "Values of x",ylab= "f(x)" )
lines(p,vec)
return (vec)
And I have this plot :我有这个情节:
I would like to smoothen the curve and get its equation in R, could you help me please?我想平滑曲线并在 R 中得到它的方程,你能帮我吗?
I cannot unfortunately reproduce your example but I would guess that this could be a good solution:不幸的是,我无法重现您的示例,但我想这可能是一个很好的解决方案:
library(ggplot2)
data_to_plot <- data.frame(p, vec)
p <- ggplot(data_to_plot, aes(x=p, y=vec)) + geom_point(pch=4) + geom_smooth(colour='black')
# Only plot
print(p)
# Dataset using for plotting
ggplot_build(p)
# Loess model as used in plot
loessMod <- loess(vec ~ p, data=data_to_plot)
Check the ggplot cheat sheet for more information on how you can make it a nice plot: https://rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf检查 ggplot 备忘单以获取有关如何使其成为一个好的情节的更多信息: https ://rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf
For more info on using the smooth curve, see: http://r-statistics.co/Loess-Regression-With-R.html有关使用平滑曲线的更多信息,请参阅: http : //r-statistics.co/Loess-Regression-With-R.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.