I have this code in 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?
I have this code in 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?
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
For more info on using the smooth curve, see: http://r-statistics.co/Loess-Regression-With-R.html