如何在stat_function中将参数设置为列表

时间:2019-03-11 10:58:49

标签: r ggplot2

示例和我想实现的目标在这里

set.seed(13231)
df <- data.frame(x = rnorm(20, 10, 1), y = rnorm(20, 0.2))


ggplot(aes(x = x, y = y), data = df) +
  geom_point() +
  stat_function(fun = function(x) 0.0 * x^2) +
  stat_function(fun = function(x) 0.005 * x^2) +
  stat_function(fun = function(x) 0.01 * x^2) +
  stat_function(fun = function(x) 0.02 * x^2) +
  stat_function(fun = function(x) 0.03 * x^2)

问题是:是否可以更改代码,使我只有stat_function一行,而浮动变量当前为c(0.0, 0.005, 0.01, 0.02, 0.03)。像stat_function(fun = function(x) c() * x^2

0 个答案:

没有答案