2016-11-10 149 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