You can add a curve using stat_function :
ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=sin)
You can also use qplot , but this is unclear if it is simpler:
qplot(c(0,2), fun=sin, stat="function", geom="line")
If your curve function is more complicated, use the lambda function. For example,
ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=function(x) sin(x) + log(x))
you can find other examples at http://kohske.wordpress.com/2010/12/25/draw-function-without-data-in-ggplot2/
kohske Mar 03 2018-11-11T00: 00Z
source share