自动增长率热图函数

huangapple go评论67阅读模式
英文:

Automated Growth rate function for heatmap

问题

我正在使用线性回归斜率创建热图。

我想制作相同类型的函数,但是不是使用线性回归斜率,而是使用增长率,如:(现值 - 过去值) / 过去值 * 100。

以下是适用于带有回归斜率热图的代码:

data.tablee$Formulation <-
  paste(data.tablee$`Formualmation Description`, data.tablee$Container, sep = "-")
data.tablee <- select(data.tablee, -c("Formualmation Description", "Container"))
# 
colnames(data.tablee)[colnames(data.tablee)=="TimePoint (weeks)"] <- "TimePoint"
colnames(data.tablee)[colnames(data.tablee)=="Stress"] <- "Temperature"

final_data <- data.frame(Formulation = sort(unique(data.tablee$Formulation)))

data.tablee$Study <- NULL

feature_list <- setdiff(colnames(data.tablee), c("TimePoint", "Temperature", "Formulation"))

for (feature in feature_list) {

  feature_data <- data.tablee[, c("TimePoint", "Temperature", "Formulation", feature)]

  feature_data <- reshape2::dcast(feature_data, Formulation + TimePoint ~ Temperature, value.var = feature)
  feature_data <- na.omit(feature_data)

  for (i in 3:ncol(feature_data)) {
    colnames(feature_data)[i] <- paste0(feature, " (", colnames(feature_data)[i], ")")

    final_data[, colnames(feature_data)[i]] <- sapply(final_data$Formulation, FUN = function(x) {
      coef(lm(as.formula(paste0("`", colnames(feature_data)[i], "`~TimePoint")),
               subset(feature_data, (Formulation == x)), na.action = na.omit))[["TimePoint"]]
    })
  }
}

rownames(final_data) <- final_data$Formulation
final_data <- abs(final_data[, -1])
heatmap(as.matrix(t(final_data)), cexCol = 1, cexRow = 1, Rowv = NA, scale = "row")

以下是从dput() 中复制部分数据的代码:

structure(list(`SE_HMWS (%)` = c(0.8, 0.7, 0.8, 0.8, 0.8, 0.9, 
0.8, 0.8, 0.8, 0.8, 0.8, 0.7, 0.8, 0.8, 0.8, 0.9, 0.8, 0.8, 0.8, 
0.8, 0.8, 0.7, 0.8, 0.8, 0.8, 0.9, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 
0.9, NA, 0.8, 1, 0.9, 0.9, 0.9, 0.8, 1.3, 1.2, 1.2, 1.4, 1.2, 
1.5, 1.3, 1.2, 1.3, 1.2, 3.2, 3, 3.1, 3.4, 3, 3.7, 3.1, 2.9, 
3, 3.1, 0.9, 0.9, 0.9, 1, 0.9, 1.1, 0.9, 0.9, 1, 0.9, 1.6, 1.4, 
1.5, 1.7, 1.5, 1.9, 1.5, 1.5, 1.6, 1.5, 5.5, 4.9, 5.1, 6, 4.9, 
6, 5.3, 5.1, 5.1, 5.3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
), `SE_Monomer (%)` = c(96.9, 97, 97, 96.8, 96.9, 96.8, 96.9, 
96.9, 96.9, 96.9, 96.9, 97, 97, 96.8, 96.9, 96.8, 96.9, 96.9, 
96.9, 96.9, 96.9

<details>
<summary>英文:</summary>

I am making an heatmap using the linear regression slop.

I want to make the same kind of function but instead of the linear regression slop I want to use the growth rate like : (Present value - Past value)/ Past Value \* 100.

Here is my code which work for the heatmap with regression slop :

data.tablee$Formulation <-
paste(data.tablee$Formualmation Description, data.tablee$Container, sep = "-")
data.tablee <- select(data.tablee,-c("Formualmation Description","Container"))

colnames(data.tablee)[colnames(data.tablee)=="TimePoint (weeks)"] <- "TimePoint"
colnames(data.tablee)[colnames(data.tablee)=="Stress"] <- "Temperature"

final_data <- data.frame(Formulation=sort(unique(data.tablee$Formulation)))

data.tablee$Study <- NULL

feature_list <- setdiff(colnames(data.tablee),c("TimePoint","Temperature","Formulation"))

for(feature in feature_list){

feature_data <- data.tablee[,c("TimePoint","Temperature","Formulation",feature)]

feature_data <- reshape2::dcast(feature_data,Formulation+TimePoint~Temperature,value.var=feature)
feature_data=na.omit(feature_data)

for(i in 3:ncol(feature_data)){
colnames(feature_data)[i] <- paste0(feature," (",colnames(feature_data)[i],")")

final_data[,colnames(feature_data)[i]] &lt;- sapply(final_data$Formulation,FUN=function(x){
  coef(lm(as.formula(paste0(&quot;`&quot;,colnames(feature_data)[i],&quot;`~TimePoint&quot;)),
          subset(feature_data,(Formulation==x)),na.action=na.omit))[[&quot;TimePoint&quot;]]
})

}
}
rownames(final_data) <- final_data$Formulation
final_data <- abs(final_data[,-1])
heatmap(as.matrix(t(final_data)),cexCol=1,cexRow=1,Rowv=NA,scale="row")



The code to reproduct part of my data from dput()

structure(list(SE_HMWS (%) = c(0.8, 0.7, 0.8, 0.8, 0.8, 0.9,
0.8, 0.8, 0.8, 0.8, 0.8, 0.7, 0.8, 0.8, 0.8, 0.9, 0.8, 0.8, 0.8,
0.8, 0.8, 0.7, 0.8, 0.8, 0.8, 0.9, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.9, NA, 0.8, 1, 0.9, 0.9, 0.9, 0.8, 1.3, 1.2, 1.2, 1.4, 1.2,
1.5, 1.3, 1.2, 1.3, 1.2, 3.2, 3, 3.1, 3.4, 3, 3.7, 3.1, 2.9,
3, 3.1, 0.9, 0.9, 0.9, 1, 0.9, 1.1, 0.9, 0.9, 1, 0.9, 1.6, 1.4,
1.5, 1.7, 1.5, 1.9, 1.5, 1.5, 1.6, 1.5, 5.5, 4.9, 5.1, 6, 4.9,
6, 5.3, 5.1, 5.1, 5.3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
), SE_Monomer (%) = c(96.9, 97, 97, 96.8, 96.9, 96.8, 96.9,
96.9, 96.9, 96.9, 96.9, 97, 97, 96.8, 96.9, 96.8, 96.9, 96.9,
96.9, 96.9, 96.9, 97, 97, 96.8, 96.9, 96.8, 96.9, 96.9, 96.9,
96.9, 96.8, 96.9, 96.8, NA, 96.8, 96.7, 96.8, 96.8, 96.8, 96.8,
95.9, 96.1, 96, 95.9, 96.1, 95.7, 96, 96, 95.9, 96.1, 91.7, 92.1,
92, 91.7, 92.1, 91.2, 92, 92.1, 92.2, 91.9, 96.7, 96.8, 96.8,
96.6, 96.7, 96.6, 96.7, 96.7, 96.7, 96.8, 95.1, 95.3, 95.2, 95,
95.3, 94.7, 95.2, 95.2, 95.2, 95.2, 86.3, 86.9, 86.8, 85.9, 87.1,
85.9, 86.6, 86.7, 87.2, 86.5, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), SE_LMWS (%) = c(2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3,
2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3,
2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.4, 2.3, 2.3,
NA, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.8, 2.7, 2.7, 2.7, 2.7, 2.8,
2.8, 2.7, 2.7, 2.7, 5, 5, 5, 4.9, 5, 5.1, 4.9, 4.9, 4.8, 5, 2.4,
2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.3, 3.3, 3.3, 3.2, 3.3,
3.3, 3.4, 3.3, 3.3, 3.2, 3.3, 8.3, 8.1, 8.1, 8.1, 8, 8.1, 8.1,
8.2, 7.7, 8.2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Study = c("STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786", "STD786", "STD786", "STD786", "STD786", "STD786", "STD786",
"STD786"), Stress = c("2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C",
"2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "25±2°C", "25±2°C",
"25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C",
"25±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C",
"40±2°C", "40±2°C", "40±2°C", "40±2°C", "2-8°C", "2-8°C", "2-8°C",
"2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C",
"25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C",
"25±2°C", "25±2°C", "25±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C",
"40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "2-8°C",
"2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C",
"2-8°C", "2-8°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C",
"25±2°C", "25±2°C", "25±2°C", "25±2°C", "25±2°C", "40±2°C", "40±2°C",
"40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C", "40±2°C",
"40±2°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C", "2-8°C",
"2-8°C", "2-8°C", "2-8°C", "2-8°C"), Container = c("Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial", "Glass vial",
"Glass vial", "Glass vial", "Glass vial", "Glass vial"), Formualmation Description = c("STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50",
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50",
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50",
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50",
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50",
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50"
), TimePoint (weeks) = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L)), row.names = 127:226, class = "data.frame")


</details>


# 答案1
**得分**: 0

以下是您的内容的中文翻译:

这里是一种使用 `tidyverse` 的方法来计算增长率,基本上意味着首先将数据重新塑造成长格式或整洁格式。然后,我们需要进行一些数据整理,并仅保留第一个和最后一个时间点:

```R
library(dplyr)
library(tidyr)
library(ggplot2)

data_tidy <- data.tablee |>
  tidyr::pivot_longer(-c(Formulation, TimePoint, Temperature), names_to = "feature") |>
  mutate(feature = paste0(feature, " (", Temperature, ")")) 

data_growth <- data_tidy |>
  arrange(Formulation, feature, TimePoint) |>
  group_by(Formulation, feature) |>
  drop_na(value) |>
  slice(c(1, n())) |>
  mutate(growth_rate = value / lag(value) - 1) |>
  drop_na(growth_rate)

data_heat <- data_growth |>
  select(Formulation, feature, growth_rate) |>
  arrange(Formulation, feature) |>
  pivot_wider(names_from = feature, values_from = growth_rate) |>
  as.data.frame()

rownames(data_heat) <- data_heat[[1]]
data_heat[[1]] <- NULL

heatmap(as.matrix(t(data_heat)), cexCol = 1, cexRow = 1, Rowv = NA, scale = "row")

自动增长率热图函数

英文:

Here is a tidyverse approach to compute your growth rates which basically means to first reshape your data to long or tidy format. Afterwards we have to do some data wrangling and keep only the first and last time point:

library(dplyr)
library(tidyr)
library(ggplot2)

data_tidy &lt;- data.tablee |&gt;
  tidyr::pivot_longer(-c(Formulation, TimePoint, Temperature), names_to = &quot;feature&quot;) |&gt;
  mutate(feature = paste0(feature, &quot; (&quot;, Temperature, &quot;)&quot;)) 

data_growth &lt;- data_tidy |&gt;
  arrange(Formulation, feature, TimePoint) |&gt; 
  group_by(Formulation, feature) |&gt;
  drop_na(value) |&gt; 
  slice(c(1, n())) |&gt; # Keep only first and last time point with non-missing data
  mutate(growth_rate = value / lag(value) - 1) |&gt; 
  drop_na(growth_rate)

data_heat &lt;- data_growth |&gt; 
  select(Formulation, feature, growth_rate) |&gt;
  arrange(Formulation, feature) |&gt; 
  pivot_wider(names_from = feature, values_from = growth_rate) |&gt;
  as.data.frame()

rownames(data_heat) &lt;- data_heat[[1]]
data_heat[[1]] &lt;- NULL

heatmap(as.matrix(t(data_heat)), cexCol = 1, cexRow = 1, Rowv = NA, scale = &quot;row&quot;)

自动增长率热图函数

huangapple
  • 本文由 发表于 2023年2月16日 16:42:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75469685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定