Plot a function with several arguments in R

前端 未结 4 2132
萌比男神i
萌比男神i 2020-12-19 22:47

Suppose I want to plot an R function:

weibull <- function(ALPHA, LAMBDA, T){
ALPHA*LAMBDA*(T^(ALPHA-1))
}

So the function takes the arg

4条回答
  •  死守一世寂寞
    2020-12-19 23:17

    This is similar to MrFlick's answer but shorter:

    par(mfrow=1:2)
    lapply(0:4, function(l) curve(weibull(0.5, 2^l, x), col=l+1, add=l!=0, ylim=c(0,50), xlim=c(0,2)))
    lapply(0:4, function(l) curve(weibull(1, 2^l, x), col=l+1, add=l!=0, ylim=c(0,50), xlim=c(0,2)))
    

    Ok if you're a big fan of nested lapply's you can also do:

    lapply(c(0.5,1), function(a) lapply(0:4, function(l) curve(weibull(a, 2^l, x), col=l+1, add=l!=0, ylim=c(0,50), xlim=c(0,2))))
    

提交回复
热议问题