Plotting a function curve in R with 2 or more variables

后端 未结 1 1816
[愿得一人]
[愿得一人] 2021-01-24 19:12

How can I draw a curve for a function like vpd = function(k,D){exp(-k*D)} in R?

I want a plot of D vs vpd(0:1) assuming k<

相关标签:
1条回答
  • 2021-01-24 20:15

    While Mamoun Benghezal's answer works for functions you define yourself, there may be cases where you want to plot a predefined function that expects more than 1 parameter. In this case, currying is a solution:

    library(functional)
    
    k <- 0.05
    
    vpd <- function(k,D){exp(-k*D)}
    vpd_given_k <- Curry(vpd, k = 0.05)
    
    curve(vpd_given_k, ylim = c(0, 1),
          from = 1, to = 100, 
          xlab = "D", ylab = paste("vpd | k = ", k))
    
    0 讨论(0)
提交回复
热议问题