This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot_fc<-function(df, key1_x, key1_y, key2_x, key2_y, plot_xlab="", plot_ylab=""){ | |
l1x<-log2(df[,key1_x] +1) | |
l1y<-log2(df[,key1_y] +1) | |
l2x<-log2(df[,key2_x] +1) | |
l2y<-log2(df[,key2_y] +1) | |
diff1 <- l1x - l1y | |
diff2 <- l2x - l2y | |
names(diff1) <- "DIFF1" | |
names(diff2) <- "DIFF2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot_ma<- function(dat, rep1, rep2, main_title=""){ | |
l1<-log2(dat[,rep1] +1) | |
l2<-log2(dat[,rep2] +1) | |
diff <- l1 - l2 | |
names(diff) <- "LOG2FC" | |
ave <- rowMeans(cbind(l1, l2), na.rm=TRUE) | |
df <- data.frame(rep1=l1, rep2=l2, "LOG2FC"=diff, "AVE_EXP"=ave, check.names = F) | |
max_y<-ceiling(max(abs(max(df$LOG2FC)),abs(min(df$LOG2FC)), 2)) | |
seq_y<-round(seq(-max_y, max_y, by = .5),1) | |
#df$OUT1<-ifelse(abs(df$LOG2FC)>1, 0,1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ggplot with equation | |
lm_eqn <- function(df, key_y, key_x){ | |
m<-lm(formula(paste(key_y,"~",key_x)), df) | |
eq <- substitute(italic(y) == b %.% italic(x) + a*","~~italic(R)^2~"="~r2, | |
list(a = formatC(coef(m)[1], digits = 4,format="f", flag="#"), | |
b = formatC(coef(m)[2], digits = 4,format = "f", flag="#"), | |
r2 = formatC(summary(m)$r.squared, digits = 4,format = "f", flag="#"))) | |
as.character(as.expression(eq)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mypca<-function(x, mytitle="", ...) | |
{ | |
par(mfrow=c(1,1)) | |
this_pc <- prcomp(x, scale=FALSE) | |
this_pc_coord <- this_pc$x | |
pc1pct=round(summary(this_pc)$importance[2,1]*100,2) | |
pc2pct=round(summary(this_pc)$importance[2,2]*100,2) | |
par(mar = c(8, 5, 3, 8), xpd=T) | |
plot(this_pc_coord[,1], this_pc_coord[,2], pch = 19, cex=2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pairs(df, lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=panel.hist) | |
panel.cor <- function(x, y, digits=2, prefix="", cex.cor) | |
{ | |
usr <- par("usr"); on.exit(par(usr)) | |
par(usr = c(0, 1, 0, 1)) | |
r <- abs(cor(x, y)) | |
txt <- format(c(r, 0.123456789), digits=digits)[1] | |
txt <- paste(prefix, txt, sep="") | |
if(missing(cex.cor)) cex <- 0.8/strwidth(txt) |