[R] Sin curve question
Jeff Newmiller
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sat Jul 24 21:42:51 CEST 2021
This is not excel-help, but to the best of my knowledge Excel interpolates with splines when you select curved point interpolation.
R, being primarily a science tool rather than a business tool, assumes you want to be precise about how new points are to be interpolated between original data points. Thus, the task of building the spline and deciding how close the points in that interpolation need to be is typically left to the user. If the user knows that the points are part of a periodic continuous function and extrapolation is desired, then choosing a fourier series may be a better choice than a spline. But the data you have provided is insufficient to support a fourier analysis, so there is some sophisticated math in between you and your goal unless you build in heuristics about how to interpolate within these points, or just live with whatever a spline function will give you... but the choice is yours to make.
On July 24, 2021 11:41:05 AM PDT, Thomas Subia via R-help <r-help using r-project.org> wrote:
>Colleagues,
>
>Here is my code which plots sin(x) vs x, for angles between 0 and 180
>degrees.
>
>library(ggplot2)
>library(REdaS)
>copdat$degrees <- c(0,45,90,135,180)
>copdat$radians <- deg2rad(copdat$degrees)
>copdat$sin_x <- sin(copdat$radians)
>
>ggplot(copdat,aes(x=degrees,y=sin_x))+
> geom_point(size = 2)+ geom_line()+
> theme_cowplot()+xlab("x")+
> ylab("sin(x)")+
> scale_x_continuous(breaks=seq(0,180,30))+
> ggtitle("sin(x) vs x\nx is in degrees")
>
>My trig students would prefer a curved line plot similar to what can be
>plotted with Excel smooth line functionality.
>I wanted to provide a relatively simple R script using ggplot to do
>this
>without having to resort to fitting a sine curve to these points.
>
>Some guidance would be appreciated.
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
More information about the R-help
mailing list