2016-11-10 279 views
1

如何绘制R中的通用sin曲线? 基于对this post答案,我想:在R中绘制正弦曲线

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

enter image description here

其实我真的会被这个图中,由gnuplot生产:

plot sin(x) linestyle 1 

enter image description here

此外,我想知道为什么gnuplot甚至产生一个图表如果我没有给变量x分配任何值。它是否有预先指定的值或其他内容?

+0

难道我的回答居然回答你的问题?关于gnuplot问题,所以标准设置是非常正常的。对我来说,图形看起来像是在无穷远处,但画布的边缘在+ -10 ... – drmariod

回答

3

pi只是一个正弦曲线的半......添加更多pi所以你会得到更多的曲线......

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

如果y是x的函数,那么可以使用'curve'如果你喜欢:'curve(sin,to = 2 * pi)' – alistaire

+0

谢谢大家的建议! – Worice