knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(MeanFlowData)

Mean Cell Type Findings from Flow Cytometry Data

Function 1 Split Data by Genotype

Split_Gen_Funct<- function(df, vect){
Split_Genotype.df<- split(df, vect)
return(Split_Genotype.df)
}

Use function in main script

Split_Genotype_list<- Split_Gen_Funct(SC_Data, SC_Data$Genotype)

#mainScript to convert the separated list into dataframes 
Het_df<- as.data.frame(Split_Genotype_list[[1]])
KO_df<- as.data.frame(Split_Genotype_list[[2]])
WT_df<- as.data.frame(Split_Genotype_list[[3]])

#remove first two columns so we can take the mean of each column:
Het_df<- Het_df[,3:14]
KO_df<- KO_df[,3:14]
WT_df<- WT_df[,3:14]

Function 2 Take the mean of each cell type per genotype (mean of each column)

```r

ColMean_funct<- function(df){

Col_Means_df<- colMeans(df)

return(Col_Means_df)

}

```

Call the function and create a matrix for each mean set

#call the function and create a matrix for each mean set
Het_means<- ColMean_funct(Het_df)
KO_means<- ColMean_funct(KO_df)
WT_means<- ColMean_funct(WT_df)

#combine the means to create matrix for function3 
TotalMeans<- cbind(Het_means, KO_means, WT_means)

Function 3 Visualize Data in a barplot to compare cell types

barplot_funct<- function(matrix){
  bar.plot<- barplot(matrix, width= 0.01, beside=TRUE, main='Mean Flow Cytometry Cell Count', xlab='Cell Types (WT, Het, KO)', ylab="Cell Count (%)", col=topo.colors(12))
                     legend("topright", ncol=4, cex=0.75, inset=.02, title="Cell Type", c("C1","C2","C3","C4", "C5", "C6", "C7", "C8", "C9","C10", "C11", "C12"), fill=topo.colors(12))
  return(bar.plot)
  }

Call function to create graph

barplot_funct(TotalMeans)

Figure 1: Compare mean cell types C1-C12 from Flow Cytometry analysis



MiaCozart/FinalProjectRepo documentation built on Dec. 31, 2020, 3:16 p.m.