R 在ggplot2中叠加多条曲线

R 在ggplot2中叠加多条曲线,r,ggplot2,R,Ggplot2,我不知道如何在ggplot2的curve()函数中复制add=TRUE参数 假设我有这个阴谋 testfn<-function(x,a){ sin(x-a) } for(i in 1:10){ curve(testfn(x,i),add=TRUE,xlim=c(-5,5)) } testfn使用lappy 乙二醇 库(ggplot2) #底图(具有x限制) xlim使用lappy 乙二醇 库(ggplot2) #底图(具

我不知道如何在ggplot2的curve()函数中复制add=TRUE参数

假设我有这个阴谋

     testfn<-function(x,a){
        sin(x-a)
    }

    for(i in 1:10){
        curve(testfn(x,i),add=TRUE,xlim=c(-5,5))
    }

testfn使用
lappy

乙二醇

库(ggplot2)
#底图(具有x限制)

xlim使用
lappy

乙二醇

库(ggplot2)
#底图(具有x限制)
xlim
 library(ggplot2)
# the base plot (with x limits)
xlim <- c(-5,5)
baseplot <- ggplot(data.frame(x = xlim), aes(x=x))

# the function
testfn <- function(x,a){sin(x-a)}
# a list of 10 calls (a = 1,...10)
list_fn <- lapply(seq_len(10), function(a){
  stat_function(fun = testfn, args = list(a=a))
})
# the plot
baseplot + list_fn