简体   繁体   中英

Plotting fit result in loop growthrate package in r

I am using fit_easylinear for my 96 well plates data. From growthrate I am using fit_easylinear for which the data should not duplicated. In my data, time is duplicated for each well (A,,A2.A3 etc), With the help of one of the stackoverflow user. I am able to run fit_easylinear in a loop but I am struggling to make the plots for fit result: The code that I have so far:

 library(growthrates)
    library(tidyverse)
    
    set.seed(11)
    
    df <- data.frame(time = seq(0, 865),
                     A1 = runif(866, 0, 1),
                     A2 = runif(866, 0, 1),
                     A3 = runif(866, 0, 1),
                     A4 = runif(866, 0, 1),
                     A5 = runif(866, 0, 1),
                     A6 = runif(866, 0, 1),
                     A7 = runif(866, 0, 1),
                     A8 = runif(866, 0, 1),
                     A9 = runif(866, 0, 1),
                     A10 = runif(866, 0, 1),
                     A11 = runif(866, 0, 1),
                     A12 = runif(866, 0, 1),
                     B1 = runif(866, 0, 1),
                     B2 = runif(866, 0, 1),
                     B3 = runif(866, 0, 1),
                     B4 = runif(866, 0, 1),
                     B5 = runif(866, 0, 1),
                     B6 = runif(866, 0, 1),
                     B7 = runif(866, 0, 1),
                     B8 = runif(866, 0, 1),
                     B9 = runif(866, 0, 1),
                     B10 = runif(866, 0, 1),
                     B11 = runif(866, 0, 1),
                     B12 = runif(866, 0, 1),
                     C1 = runif(866, 0, 1),
                     C2 = runif(866, 0, 1),
                     C3 = runif(866, 0, 1),
                     C4 = runif(866, 0, 1),
                     C5 = runif(866, 0, 1),
                     C6 = runif(866, 0, 1),
                     C7 = runif(866, 0, 1),
                     C8 = runif(866, 0, 1),
                     C9 = runif(866, 0, 1),
                     C10 = runif(866, 0, 1),
                     C11 = runif(866, 0, 1),
                     C12 = runif(866, 0, 1))
    
    
    
    
    ###################### fit easy linear model 
    
    
    fit_list <- lapply(2:length(colnames(df)), function(x) fit_easylinear(df$time, df[[x]]))
    

######This plots all the values but dose not show the actual fit for (i in seq_along(fit_list)) {jpeg(paste0("C:/Users/Desktop/images/", colnames(df)[i+1], ".jpg")); plot(slot(fit_list[[i]], "obs")); dev.off() }

###### removed slot from the code
    
 for (i in seq_along(fit_list)) {jpeg(paste0("C:/Users/Rahul/Desktop/images", colnames(df)[i+1], ".jpg"));plot(fit_list[[i]]) ;dev.off()}    
    

From th above line of code gives me error as Error in seq.default(min(obs[, "time"] + lag), max(obs[, "time"]), length = 200) : 
      'from' must be a finite number

As said in my previous answer it is almost always better to work with data in long format, especially as the package explicitly supports this. However, the result of the lapply call used by the original poster can also be plotted.

Instead of purely random data, let's use another, little bit more realistic example of an exponentially growing population:

df <- data.frame(
  time = 1:10,
  A1 = c(1.12, 1.27, 1.18, 1.49, 1.58, 1.84, 2.19, 2.32, 2.6, 2.72),
  A2 = c(1.23, 1.54, 1.65, 2.23, 2.65, 3.33, 4.23, 5.04, 6.19, 7.39),
  A3 = c(1.36, 1.87, 2.29, 3.32, 4.42, 6.06, 8.34, 11.11, 15.02, 20.09),
  B1 = c(1.5, 2.27, 3.15, 4.96, 7.32, 11.04, 16.62, 24.62, 36.74, 54.6),
  B2 = c(1.66, 2.77, 4.31, 7.39, 12.12, 20.1, 33.29, 54.69, 90.16, 148.42),
  B3 = c(1.84, 3.37, 5.88, 11.03, 20.02, 36.61, 66.86, 121.6, 221.55, 403.43)
)

fit_list <- lapply(2:length(colnames(df)), function(x) fit_easylinear(df$time, df[[x]]))

par(mfrow=c(2, 3))
dummy <- lapply(fit_list, plot) 

The dummy variable is just intended to suppress the unnecessary output of lapply . One can also enclose the lapply within invisible() .

绘制生长曲线

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM