library(lattice);
library(ggplot2); library(htmltools);library(gridExtra);library(plotly); library(heatmaply);
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
## Loading required package: viridis
## Loading required package: viridisLite
##
## ---------------------
## Welcome to heatmaply version 0.10.1
## Type ?heatmaply for the main documentation.
## The github page is: https://github.com/talgalili/heatmaply/
##
## Suggestions and bug-reports can be submitted at: https://github.com/talgalili/heatmaply/issues
## Or contact: <tal.galili@gmail.com>
##
## To suppress this message use: suppressPackageStartupMessages(library(heatmaply))
## ---------------------
x <- read.table(file = "~/Documents/CUNY/biostat/prepropmetabolites.txt", header = T, sep = "\t", strip.white = T, na.strings = T)
x$meanArea <- rowMeans(x[,3:8], na.rm = T)
head(x)
## Mutant Formula Neg_R1 Neg_R2 Neg_R3 Pos_R1 Pos_R2
## 1 F22031 C11H12N2O2 NA NA NA 10.83984 12.25409
## 2 F22031 C6H12N2O3 NA NA NA 57.96802 58.64407
## 3 F22031 C3H6O3 10.334892 5.308771 2.467689 NA NA
## 4 F22031 C7H10O4 2.873870 3.090740 2.710957 NA NA
## 5 F22031 C3H4O2 1.024696 1.134164 1.336829 NA NA
## 6 F22031 C6H10O5 20.681327 21.532134 19.862744 NA NA
## Pos_R3 meanArea
## 1 5.777178 9.623700
## 2 50.387960 55.666682
## 3 NA 6.037117
## 4 NA 2.891856
## 5 NA 1.165230
## 6 NA 20.692068
hist(x$meanArea, breaks = 300, main = "Histogram of meanArea", xlab = "meanArea")

hist(log(x$meanArea), breaks = 300, main = "Histogram of log meanArea", xlab = "log meanArea")

hist(log10(x$meanArea), breaks = 200, main = "Histogram of log10 meanArea", xlab = "log10 meanArea")

barchart(~log10(meanArea) | Formula, group = Mutant, data=x)

x.split.by.formula <- split(x, x$Formula)
x.zscore <- lapply(x.split.by.formula, function(x) (x$meanArea - mean(x$meanArea, na.rm = T))/sd(x$meanArea, na.rm=T))
x.zscore.df <- as.data.frame(x.zscore)
rownames(x.zscore.df) <- as.character(x.split.by.formula[[1]]$Mutant)
x.zscore.mat <- as.matrix(x.zscore.df)
colfunc <- colorRampPalette(c("blue", "royalblue", "orange", "red")) # customize color palette
heatmaply(x.zscore.mat, colfunc(14), scale = "column",
label_names = c("Strain", "Compound", "Zscore"),
cexCol = 7, margins = c(130, 80), main = "Heatmap of standardized mean area",
ylab = "strain", xlab = "compound")
## Warning in doTryCatch(return(expr), name, parentenv, handler): unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
## dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
## Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so
## Reason: image not found
INTERACTIVE MAP