koh*_*ske 74
您可以使用以下命令添加曲线stat_function:
ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=sin)
Run Code Online (Sandbox Code Playgroud)
它也可以使用qplot,但不清楚这是否更简单:
qplot(c(0,2), fun=sin, stat="function", geom="line")
Run Code Online (Sandbox Code Playgroud)
如果曲线函数更复杂,则使用lambda函数.例如,
ggplot(data.frame(x=c(0, 10)), aes(x)) +
stat_function(fun=function(x) sin(x) + log(x))
Run Code Online (Sandbox Code Playgroud)
你可以在http://kohske.wordpress.com/2010/12/25/draw-function-without-data-in-ggplot2/找到其他例子.
| 归档时间: |
|
| 查看次数: |
22708 次 |
| 最近记录: |