Error in labeledHeatmap(Matrix = moduleTraitCor, xLabels = colnames(design), : Length of 'xLabels' must equal the number of columns in 'Matrix.'
用以前的代码,跑其他的样本第5步的时候出现了
STEP5:模块和性状的关系
MEs是一个关于modules的特征量矩阵,行数等于筛选的modules数,列数等于样本数;
if(T){
nGenes = ncol(datExpr)
nSamples = nrow(datExpr)
design=model.matrix(~0+ datTraits$ClinicalTraits)
colnames(design)=levels(datTraits$ClinicalTraits)
moduleColors <- labels2colors(net$colors)
# Recalculate MEs with color labels
MEs0 = moduleEigengenes(datExpr, moduleColors)$eigengenes
MEs = orderMEs(MEs0); ##不同颜色的模块的ME值矩 (样本vs模块)
moduleTraitCor = cor(MEs, design , use = "p");
moduleTraitPvalue = corPvalueStudent(moduleTraitCor, nSamples)
sizeGrWindow(10,6)
# Will display correlations and their p-values
textMatrix = paste(signif(moduleTraitCor, 2), "\n(",
signif(moduleTraitPvalue, 1), ")", sep = "");
dim(textMatrix) = dim(moduleTraitCor)
png("step5-Module-trait-relationships.png",width = 800,height = 1200,res = 120)
#pdf("step5-Module-trait-relationships.pdf",width = 36, height = 36)
par(mar = c(6, 8.5, 3, 3));
# Display the correlation values within a heatmap plot
labeledHeatmap(Matrix = moduleTraitCor,
xLabels = colnames(design),
yLabels = names(MEs),
ySymbols = names(MEs),
colorLabels = FALSE,
colors = greenWhiteRed(50),
textMatrix = textMatrix,
setStdMargins = FALSE,
cex.text = 0.5,
zlim = c(-1,1),
main = paste("Module-trait relationships"))
dev.off()
}
报错信息:
Error in labeledHeatmap(Matrix = moduleTraitCor,
xLabels = colnames(design), :
Length of 'xLabels' must equal the number of columns in 'Matrix.'
出图的时候错了。搜索也找不到答案,不知道如何解决。
colnames(design)
的结果为null
,把colnames(design)
转化为因子也不能解决。
今天(2020.02.13)把上面的问题解决了,的确是把colnames(design)
转化为因子。准确的说应该是吧。design转化为因子。
colnames(design)=levels(as.factor(datTraits$ClinicalTraits))
但是会有警告信息,不过不影响结果:
Warning message:
In greenWhiteRed(50) :
WGCNA::greenWhiteRed: this palette is not suitable for people
with green-red color blindness (the most common kind of color blindness).
Consider using the function blueWhiteRed instead.
网友评论