r - Plotting multiple plots for different initial conditions in one graph - Stack Overflow

I am using the following code. How can I plot time (x-axis) vs C_WT (y-axis) line plots for different C

I am using the following code. How can I plot time (x-axis) vs C_WT (y-axis) line plots for different C_WT values as in vectorC_WT in a single graph in R ?

kon_WT = 1         
koff_WT = 10
R_WT =   20
Complex <- function (t,y,parms){
with(as.list(y), {

dC_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
dRL_WT <- kon_WT*R_WT*C_WT - koff_WT*RL_WT   #uM
dR_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 

return(list(c(dC_WT, dRL_WT, dR_WT)))
})
}
resC_WT <- function(iC_WT) {
 times <- seq(0,1,0.01)
 Out <- ode(y = c(C_WT = iC_WT, RL_WT = 0, R_WT= R_WT), times = times, func=Complex, 
parms=NULL)
Output <- data.frame(Out)
}

vectorC_WT <- 1:11
sapply(vectorC_WT, FUN=resC_WT)
Complex1 <- as.data.frame(t(Complex1))

I am using the following code. How can I plot time (x-axis) vs C_WT (y-axis) line plots for different C_WT values as in vectorC_WT in a single graph in R ?

kon_WT = 1         
koff_WT = 10
R_WT =   20
Complex <- function (t,y,parms){
with(as.list(y), {

dC_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
dRL_WT <- kon_WT*R_WT*C_WT - koff_WT*RL_WT   #uM
dR_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 

return(list(c(dC_WT, dRL_WT, dR_WT)))
})
}
resC_WT <- function(iC_WT) {
 times <- seq(0,1,0.01)
 Out <- ode(y = c(C_WT = iC_WT, RL_WT = 0, R_WT= R_WT), times = times, func=Complex, 
parms=NULL)
Output <- data.frame(Out)
}

vectorC_WT <- 1:11
sapply(vectorC_WT, FUN=resC_WT)
Complex1 <- as.data.frame(t(Complex1))
Share Improve this question edited Mar 3 at 7:10 tpetzoldt 5,8382 gold badges13 silver badges32 bronze badges asked Mar 3 at 5:55 KhushhiKhushhi 635 bronze badges 1
  • 1 Please correct your code so that it runs without error. – Edward Commented Mar 3 at 6:04
Add a comment  | 

1 Answer 1

Reset to default 1

Here a simple solution, using lists and the built-in plotfunction of deSolve. It accepts one single run as first argument and a list of runs as its second argument.

To make it work, remove the as.data.frame-conversion and use lapply instead of sapply.

library(deSolve)

kon_WT <- 1         
koff_WT <- 10
R_WT <-   20
Complex <- function (t,y,parms){
  with(as.list(y), {
    
    dC_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
    dRL_WT <- kon_WT*R_WT*C_WT - koff_WT*RL_WT   #uM
    dR_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
    
    return(list(c(dC_WT, dRL_WT, dR_WT)))
  })
}
resC_WT <- function(iC_WT) {
  times <- seq(0,1,0.01)
  Out <- ode(y = c(C_WT = iC_WT, RL_WT = 0, R_WT= R_WT), times = times, func=Complex, 
             parms=NULL)
  Out
}

vectorC_WT <- 1:11

result <- lapply(vectorC_WT, FUN=resC_WT)

plot(result[[1]], result)

If you wish a plot of only a single state variable, use which:

plot(result[[1]], result, which = "C_WT")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745108195a4611684.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信