Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot sine curve in R

Tags:

plot

r

gnuplot

How can I plot a generic sin curve in R? Based on the answer of this post, I tried:

x <- seq(0,pi,length.out=100)
y <- sin(x)
plot(x,y,type="l")

enter image description here

Actually what I really would is this graph, produced by gnuplot:

plot sin(x) linestyle 1

enter image description here

Furthermore, I would like to know why gnuplot produces a graph even if I do not assign any value to the variable x. Does it have a preassigned value or something else?

like image 366
Worice Avatar asked Nov 10 '16 15:11

Worice


People also ask

How do you plot a sin curve?

To graph the sine function, we mark the angle along the horizontal x axis, and for each angle, we put the sine of that angle on the vertical y-axis. The result, as seen above, is a smooth curve that varies from +1 to -1. Curves that follow this shape are called 'sinusoidal' after the name of the sine function.

How do you create a sine function in R?

Calculate sine of a value in R Programming – sin() Functionsin() function in R Language is used to calculate the sine value of the numeric value passed to it as argument.


1 Answers

pi is just one half of a sine curve... add more pi so you will get more curves...

x <- seq(0,8*pi,length.out=100)
y <- sin(x)
plot(x,y,type="l")
like image 134
drmariod Avatar answered Oct 03 '22 10:10

drmariod