功能绘图的简单示例:
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = function(x) x^2 + 1*2)
Run Code Online (Sandbox Code Playgroud)
是否可以在ggplot中的绘图代码中添加参数列表?像这样的东西?
fun1 <- function(x) x^2 + a*b
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = fun1, par=list(a=1, b=2)) + xlim(-5,5)
Run Code Online (Sandbox Code Playgroud)
像这样?
fun1 <- function(x,a,b) a*x^2 + b
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p +
stat_function(fun = fun1, args=list(a=1, b=2)) +
stat_function(fun = fun1, args=list(a=2, b=1), col='red') +
xlim(-5,5)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
448 次 |
| 最近记录: |