2016-09-15 27 views
2

ggplot2でプロットされた三角関数の曲線がギザギザに見えます。ggplot2三角関数のプロットがギザギザに見える

library(ggplot2) 
ggplot(data.frame(x = c(-0.2,0.2)), aes(x = x)) + 

stat_function(fun = function(x) cos(pi/x) , geom = "line") 

はこのギザギザプロット与える:

enter image description here

をしかし、私はこのような、よりスムーズなプロット期待していた。このことについて

enter image description here

+3

増加 'N'。 '?stat_function'を参照してください。 – Axeman

答えて

5

どのように?

library(ggplot2) 

ggplot(data.frame(x = c(-2.5,2.5)), aes(x = x)) + 
     stat_function(fun = function(x) ifelse(x!=0, cos(pi/x), 0), 
     geom = "line", n=5000, col='blue') 

enter image description here

+0

限界としてゼロを使用すると痛いです。少なくとも「NA」を使用してください。 (プロットは変更されません) – Roland

+0

もちろん、NA @Roland –

関連する問題