我正在尝试将绘图的代码从基础R转换为利用UNION DISTINCT
库。这是绘图的代码,以及图像。 plotly
是一个正在读入的表(在此处的代码上方),其中包含不同GSE#的组之间的对比。 (有关详细信息,请参阅here)
contrastTable
除了情节明显的间距/缩放问题外,我还有两个主要问题。
1)如何在#Get gene to plot
gene = toupper(readline(prompt="Enter gene name (e.g. GZMA): "))
#Find all instances of query gene in master contrast table
geneLines = grep(paste("^",gene,"$",sep = ""),contrastTable[,"gene"])
#If the gene is found at least once, continue
if (length(geneLines)>0)
{
########Plot contrasts
par(oma = c(1,10,1,1))
geneRows = contrastTable[geneLines,]
fcs = as.list(geneRows$logFC)
names(fcs) = paste(geneRows$GSE,"\n",geneRows$Group2," \U2192 ",geneRows$Group1,sep = "")
maxFC = max(as.numeric(as.character(geneRows$logFC)))
minFC = min(as.numeric(as.character(geneRows$logFC)))
#Set up marker color and type
markers = rep(4,length(fcs))
markers[which(as.numeric(as.character(geneRows[,"adj.P.Val"]))<0.05)] = 15
markers[which(as.numeric(as.character(geneRows[,"adj.P.Val"]))<0.01)] = 19
outerCol = rep("grey20",length(fcs))
outerCol[which(as.numeric(as.character(geneRows[,"adj.P.Val"]))<0.05)] = "darkorange"
outerCol[which(as.numeric(as.character(geneRows[,"adj.P.Val"]))<0.01)] = "red"
layout(t(c(1,2)), c(3.5,1), c(1,1))
#Plot all contrasts
stripchart(fcs,xlim = c(min(-2,minFC),max(2,maxFC)),las = 1,col = outerCol,pch = markers,main = gene,xlab = expression(paste("log"[2],"(Fold Change)")),cex.axis=0.75)
abline(v = 0,col = "grey50",lty=2)
abline(v = log(c(0.5,2/3,1.5,2),2),col = "grey80",lty=2)
usr = par("usr")
legend(usr[1]-(usr[2]-usr[1])/3.5,usr[3]-(usr[4]-usr[3])/10,c("p \u2265 0.05","p < 0.05","p < 0.01"),col = c("black","darkorange","red"),pch = c(4,15,19),cex = 0.7,xpd = TRUE)
#add confidence interval
for (i in 1:nrow(geneRows))
{
segments(geneRows[i,"CI.L"],i,geneRows[i,"CI.R"],i,col = "grey50")
}
#Re-plot to put markers on top
par(new=TRUE)
stripchart(fcs,xlim = c(min(-2,minFC),max(2,maxFC)),las = 1,col = outerCol,pch = markers,xlab = "",ylab = "",xaxt = "n",yaxt="n")
#add lines dividing different GSE#s
datasetList = geneRows$GSE
hLines =(which(duplicated(datasetList) == FALSE) - 0.5)
abline(h = hLines, col = "grey80")
中重新创建每个GSE#之间的水平线? (现在目前由最后两行代码完成)
2)如何在plotly
中重新显示y轴,它显示GSE#,在下面显示plotly
种格式?
非常感谢任何帮助!