r 火山阴谋

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 火山阴谋相关的知识,希望对你有一定的参考价值。

plot.volcano <- function(pvalues, coefs, coefnames
						 , max.pval, min.abs.coef, trans.y="log10"
						 , remove.uninteresting.pValue.range=FALSE){
	trans.y.func <- match.fun(trans.y)	
	pval.interesting <- pvalues < max.pval
	coef.interesting <- abs(coefs) > min.abs.coef
	both.interesting <- pval.interesting & coef.interesting
	names <- ifelse(both.interesting, coefnames, "")
	
	
	max.pval <- trans.y.func(max.pval)
	line.df <- as.data.frame(rbind(c(-Inf, max.pval, -min.abs.coef, max.pval)
								   ,c(-min.abs.coef, max.pval, -min.abs.coef, -Inf)
								   # ,c(-min.abs.coef, -Inf, min.abs.coef, -Inf)
								   ,c(min.abs.coef, -Inf, min.abs.coef, max.pval)
								   ,c(min.abs.coef, max.pval, Inf, max.pval)))
	colnames(line.df) <- c("x", "y", "xend", "yend")
	
	tmp.df <- data.frame("coef"=coefs
						 ,"pvalue"=pvalues
						 ,"both.interesting"=both.interesting
						 ,"names"=names)
	p0 <- ggplot(tmp.df, aes(x=coef, y=pvalue, col=both.interesting, label=names)) + 
		geom_point()  +
		geom_text(col="darkgreen", size=2, vjust=0, hjust=0)+
		xlim(1.5*c(-min.abs.coef, min.abs.coef))
	for(lineN in 1:nrow(line.df)){
		p0 <- p0 + geom_segment(x = line.df$x[lineN], y = line.df$y[lineN]
								, xend = line.df$xend[lineN], yend = line.df$yend[lineN], col="black")
	}
	
	if(remove.uninteresting.pValue.range){
		p0 <- p0 + 
			scale_y_continuous(trans=trans.y, limits=c(-Inf, 10^max.pval))
	}else{
		p0 <- p0 + scale_y_continuous(trans=trans.y)
	}
	
	return(p0)
}

以上是关于r 火山阴谋的主要内容,如果未能解决你的问题,请参考以下文章

R语言可视化:火山图绘制

R语言绘制火山图(volcano plot)实战:为差异表达基因(DEGs)添加颜色基于显著性阈值进行点的颜色美化为选定基因添加标签

基因差异火山图怎么看

R语言入门06:GEO数据库中数据的下载

Seaborn 热图阴谋失败

小阴谋家和球拍