本文介绍了求出生长曲线的最大梯度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ggplot2制作了具有四个生长曲线的图形.

I have made a graph with four growth curves using ggplot2.

希望下面的代码可以在任何人想要尝试的情况下产生图形.

Hopefully the code below should produce the graph if anyone wants to try.

我想找到每条线上的最大斜率的值,该值超过了4个时间点.

I want to find a value for the maximum slopes on each of the lines, taken over say 4 time points.

任何人都可以提出解决方案的想法吗?

Can anyone give any ideas how to go about this?

library(ggplot2)
dat <- structure(list(TIME = c(0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L,
                           18L, 20L, 22L, 24L, 26L, 28L, 30L, 0L, 2L, 4L, 6L, 8L, 10L, 12L,
                           14L, 16L, 18L, 20L, 22L, 24L, 26L, 28L, 30L, 0L, 2L, 4L, 6L,
                           8L, 10L, 12L, 14L, 16L, 18L, 20L, 22L, 24L, 26L, 28L, 30L, 0L,
                           2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L, 22L, 24L, 26L,
                           28L, 30L), OD600 = c(0.2202, 0.2177, 0.2199, 0.2471, 0.2834,
                                                0.357, 0.4734, 0.647, 0.898, 1.1959, 1.3765, 1.3978, 1.3948,
                                                1.3928, 1.3961, 1.4018, 0.24, 0.2317, 0.2328, 0.2522, 0.2748,
                                                0.3257, 0.4098, 0.5455, 0.7387, 0.9904, 1.2516, 1.3711, 1.3713,
                                                1.3703, 1.3686, 1.3761, 0.2266, 0.2219, 0.2245, 0.2401, 0.2506,
                                                0.2645, 0.3018, 0.3484, 0.4216, 0.5197, 0.666, 0.872, 1.1181,
                                                1.2744, 1.3079, 1.2949, 0.2389, 0.2242, 0.2315, 0.2364, 0.2372,
                                                0.2373, 0.2306, 0.2385, 0.236, 0.2331, 0.2379, 0.2334, 0.2336,
                                                0.2339, 0.2389, 0.2349), MMS = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                                                 0, 0, 0, 0, 0, 0, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005,
                                                                                 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005,
                                                                                 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
                                                                                 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02,
                                                                                 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02)), .Names = c("TIME",
                                                                                                                                                          "OD600", "MMS"), class = "data.frame", row.names = c(NA, -64L
                                                                                                                                                                                                               ))
graph = ggplot(data=dat, aes(x=TIME, y=OD600))
graph + geom_line(aes(colour=factor(MMS)), alpha=1) +
opts(title="Log growth curves: change in cell density with increasing concentrations of MMS")+
scale_y_log10()

非常感谢

推荐答案

像这样吗?

cbind(
  MMS = unique(dat$MMS),
  do.call(
    rbind,
    lapply(
      unique(dat$MMS),
      function(x) {
        tdat <- dat[dat$MMS == x, ]
        response <- tdat$OD600
        timepoints <- tdat$TIME
        rise <- (response[4:length(response)] - response[1:(length(response) - 3)])
        run <- (timepoints[4:length(timepoints)] - timepoints[1:(length(timepoints) - 3)])
        slopes <- c(rep(NA, 3), rise/run)
        return(
          list(
            max_slope = max(slopes, na.rm = T),
            time = timepoints[which(slopes == max(slopes, na.rm = T)) - 3]
          )
        )
      }
    )
  )
)

赠予:

     MMS   max_slope   time
[1,] 0     0.1215833   14
[2,] 0.005 0.1176833   14
[3,] 0.01  0.1014      20
[4,] 0.02  0.002166667 2

这篇关于求出生长曲线的最大梯度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 22:38