5

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?

Community
  • 1
  • 1
Worice
  • 3,847
  • 3
  • 28
  • 49
  • Did my answer actually answer your question? About the gnuplot question, so it is pretty normal to have standard settings. For me the graph looks like it is going until infinity but the edges of the canvas are at +-10... – drmariod Nov 11 '16 at 06:58

2 Answers2

13

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")
drmariod
  • 11,106
  • 16
  • 64
  • 110
0
plot(sin, 0, 2*pi)

Change the multiplier to change the "frequency."

Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41
Andy
  • 1