R 如何在stat_函数中为列表设置参数

R 如何在stat_函数中为列表设置参数,r,ggplot2,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) +

我想要实现的例子和目标就在这里

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)
set.seed(13231)

df您可以使用
lappy

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

帮助(“+.gg”)

用法:e1%+%e2

e1:类ggplot()或主题()的对象

e2:绘图组件,如下所述

您可以添加什么?

您还可以提供一个列表,在这种情况下,列表中的每个元素都将依次添加