r - ggplot2 plot of trigonometric function looks jagged -


the curves of trigonometric function plotted ggplot2 looks jagged.

library(ggplot2) ggplot( data.frame( x = c(-0.2,0.2)), aes( x = x)) +   stat_function( fun = function(x) cos( pi/x)   , geom = "line") 

gives jagged plot:

enter image description here

but expecting more smooth plot this:

enter image description here

how this?

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


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -