简体   繁体   English

带有参数范围的ggplot2绘图函数

[英]ggplot2 plotting function with range of arguments

I would like to plot the following function, using ggplot2. 我想使用ggplot2绘制以下函数。

change <- function(score, d, k, p) {k*(score - 1/(1+k^(d/p)))}

I would like to see the results as a function of argument d. 我希望将结果视为参数d的函数。 What's wrong with the following code? 以下代码有什么问题?

library(ggplot2)
ggp <- ggplot(data.frame(x=c(0:10)), aes(x)) + 
    stat_function(fun=change, args=list(1, x, 100, 400))
ggp

Pass the arguments as a named list(without x ) works: 将参数作为命名列表(不带x )传递:

ggp <- ggplot(data.frame(x=c(0:10)), aes(x)) + 
    stat_function(fun=change, args=list(score=1, k=100, p=400))

From the help page : 从帮助页面

args: list of additional arguments to pass to fun args:传递给fun的其他参数列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM