This is a test version of Biostars. For the public version, visit https://www.biostars.org.
WGCNA package in R: dendogram plot error

Hi, I am new to WGCNA and I am trying to plot a dendogram using WGCNA package in R.

plotDendroAndColors(sampleTree2, traitColors,
>                     groupLabels = names(datTraits),
>                     main = "Sample dendrogram and trait heatmap")

This is the error I get:

Error in plotOrderedColors(dendro$order, colors = colors, rowLabels = rowLabels, : ERROR: length of colors vector not compatible with number of objects in 'order'.

Any ideas on how to resolve this? Many thanks!

wgcna r

Thanks for pointing that out! Sorry I am quite new to all this, I have removed the same post on the other site. Thanks!

Zyr123, Were you able to fix the problem, I'm having the same problem. Thanks!

Also running into the same issue. Anyone able to get is working? Thanks!

mine was running this part though:

> plotDendroAndColors(geneTree,
>                     cbind(moduleColors, bwModuleColors),
>                     c("Single block", "2 blocks"),
>                     main = "Single block gene dendrogram and module colors",
>                     dendroLabels = FALSE, hang = 0.03,
>                     addGuide = TRUE, guideHang = 0.05)

Error in plotOrderedColors(dendro$order, colors = colors, rowLabels = rowLabels, : ERROR: length of colors vector not compatible with number of objects in 'order'.

This is my net

net = blockwiseModules(datExpr, power = 6,
                       TOMType = "unsigned", minModuleSize = 30,
                       reassignThreshold = 0, mergeCutHeight = 0.25,
                       numericLabels = TRUE, pamRespectsDendro = FALSE,
                       saveTOMs = TRUE,
                       saveTOMFileBase = "All_sample_TOM", 
                       verbose = 3)

And this is my bwnet

bwnet = blockwiseModules(datExpr, maxBlockSize = 2000,
                         power = 6, TOMType = "unsigned", minModuleSize = 30,
                         reassignThreshold = 0, mergeCutHeight = 0.25,
                         numericLabels = TRUE,
                         saveTOMs = TRUE,
                         saveTOMFileBase = "All_sample_TOM-blockwise",
                         verbose = 3)

I have 6720 genes (RNA-Seq data)

You might had delete the outliers from the expression table but then the traits data.frame doesn't match with expression table dimensions.

3 answers

Hi,

blockwiseModules function have a default max block size of 5000. Thus your data is split in 2 blocks ...2 dendrograms are produced each for cca. half of your genes...the module membership objects (moduleColors, bwModuleColors) however are both of the total length. So when you call a dendrogram it's "order" object is shorter than objects (moduleColors, bwModuleColors) and you get an error.

fix: 1) set maxBlochSize=7000 and you will get a single dendro for all genes 2) or subset the genes in (moduleColors, bwModuleColors) to contain only the ones in block 1 and then match dendro1 with sub setted moduleColors

and read this : https://labs.genetics.ucla.edu/horvath/htdocs/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/FemaleLiver-02-networkConstr-blockwise.pdf

How can I extract gene lists from blocks and dendros?

When I got this error in the past, it was because I had removed a few outliers from the expression data object (datExpr0), and this was no longer matching the samples described in datTraits object. Be sure that the number of samples match between the metadata object and the expression object.

In case some other people run into this problem, if increasing your block size does not solve the problem, the "blockwiseModules" removes genes that have "too many missing samples or zero variance". However, "bwnet$colors" and "bwnet$unmergedColors" contain all the genes, but the dendrogram contains only the GOOD genes. I solved the problem by removing the BAD genes as follows:

bwnet$colors <- bwnet$colors[bwnet$goodGenes]

bwnet$unmergedColors <- bwnet$unmergedColors[bwnet$goodGenes]

Log in to answer this question.