This is a test version of Biostars. For the public version, visit https://www.biostars.org.
WGCNA: Error in plot.window(...) : need finite 'ylim' values

I am trying to learn WGCNA through this tutorial. During the network construction step I am getting this error Error in plot.window(...) : need finite 'ylim' values I have not modified the code, just copy pasted it. there are many other such questions on google but most of them says you need to remove NA's. when I type ylim it gives me this

NA   NA   NA  33.92194
NA   NA   NA 202.30723

it is all NAs, I am also using the example data provided in the tutorial. Here is the block of code which gives the error

# Choose a set of soft-thresholding powers
powers = c(seq(4,10,by=1), seq(12,20, by=2));
# Initialize a list to hold the results of scale-free analysis
powerTables = vector(mode = "list", length = nSets);
# Call the network topology analysis function for each set in turn
for (set in 1:nSets)
powerTables[[set]] = list(data = pickSoftThreshold(multiExpr[[set]]$data, powerVector=powers,
verbose = 2)[[2]]);
collectGarbage();
# Plot the results:
colors = c("black", "red")

# Will plot these columns of the returned scale free analysis tables
plotCols = c(2,5,6,7)
colNames = c("Scale Free Topology Model Fit", "Mean connectivity", "Median connectivity",
"Max connectivity");
# Get the minima and maxima of the plotted points
ylim = matrix(NA, nrow = 2, ncol = 4);
for (set in 1:nSets)
{
for (col in 1:length(plotCols))
2
{
ylim[1, col] = min(ylim[1, col], powerTables[[set]]$data[, plotCols[col]], na.rm = TRUE);
ylim[2, col] = max(ylim[2, col], powerTables[[set]]$data[, plotCols[col]], na.rm = TRUE);
}
}
# Plot the quantities in the chosen columns vs. the soft thresholding power
sizeGrWindow(8, 6)
#pdf(file = "Plots/scaleFreeAnalysis.pdf", wi = 8, he = 6)
par(mfcol = c(2,2));
par(mar = c(4.2, 4.2 , 2.2, 0.5))
cex1 = 0.7;
for (col in 1:length(plotCols)) for (set in 1:nSets)
{
if (set==1)
{
plot(powerTables[[set]]$data[,1], -sign(powerTables[[set]]$data[,3])*powerTables[[set]]$data[,2],
xlab="Soft Threshold (power)",ylab=colNames[col],type="n", ylim = ylim[, col],
main = colNames[col]);
addGrid();
}
if (col==1)
{
text(powerTables[[set]]$data[,1], -sign(powerTables[[set]]$data[,3])*powerTables[[set]]$data[,2],
labels=powers,cex=cex1,col=colors[set]);
} else
text(powerTables[[set]]$data[,1], powerTables[[set]]$data[,plotCols[col]],
labels=powers,cex=cex1,col=colors[set]);
if (col==1)
{
legend("bottomright", legend = setLabels, col = colors, pch = 20) ;
} else
legend("topright", legend = setLabels, col = colors, pch = 20) ;
}
dev.off();

I would really appreciate if someone can clarify what is wrong here. Thanks

r wgcna

How did you produce the multiExpr object?

In part one of the tutorial the authors created multiExpr object like this

# We work with two sets:
nSets = 2;
# For easier labeling of plots, create a vector holding descriptive names of the two sets.
setLabels = c("Female liver", "Male liver")
shortLabels = c("Female", "Male")
# Form multi-set expression data: columns starting from 9 contain actual expression data.
multiExpr = vector(mode = "list", length = nSets)
multiExpr[[1]] = list(data = as.data.frame(t(femData[-c(1:8)])));
names(multiExpr[[1]]$data) = femData$substanceBXH;
rownames(multiExpr[[1]]$data) = names(femData)[-c(1:8)];
multiExpr[[2]] = list(data = as.data.frame(t(maleData[-c(1:8)])));
names(multiExpr[[2]]$data) = maleData$substanceBXH;
rownames(multiExpr[[2]]$data) = names(maleData)[-c(1:8)];
# Check that the data has the correct format for many functions operating on multiple sets:
exprSize = checkSets(multiExpr)

1 answer

Following the tutorial exactly in this order, you should not have any error messages (I just did it now):

  1. Data input and cleaning
  2. One-step automatic network construction and module detection

The input data to use is found HERE, under the heading Data description and download.

j

Kevin

I am following it exactly as it is, just copying and pasting all the code. I even tried it on just R instead on Rstudio. How come I am not able to do it.

Check that every command has completed successfully. Also, update your version of WGCNA. I used the following package version to complete the tutorial:

  • WGCNA_1.68
  • fastcluster_1.1.25
  • dynamicTreeCut_1.63-1

Thanks for your time Kevin. I updated every package I have but still it gives me the same error. However I found the solution. The error only comes when I copy the code from the pdf but it works totally fine when I copy it from the Rscript.

Log in to answer this question.