clusterExperiment
clusterExperiment copied to clipboard
plotHeatmap breaks when sampleData is ordered factor
I opened this as separate issue (submitted by @allonw); was previously combined with another issue.
When one of the sampleData metadata has spaces, plotHeatmap breaks with an error that doesn't report what's wrong
library(clusterExperiment)
aaa = matrix(runif(100), nrow = 10)
anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = TRUE)
levels(anno) = c("low activity", "medium activity", "high activity")
#Error in cut.default(a, breaks = 100) : 'x' must be numeric
plotHeatmap(data = aaa, sampleData = as.data.frame(anno))
#works, but ignores the order of the factor
plotHeatmap(data = aaa, sampleData = as.data.frame(make.names(anno)))
This is something to do with how aheatmap treats ordered factors. If the factor is not ordered, the spaces are okay:
anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = FALSE)
levels(anno) = c("low activity", "medium activity", "high activity")
plotHeatmap(data = aaa, sampleData = as.data.frame(anno))
The annCol object that is being passed to aheatmap is exactly the same as as.data.frame(anno).
The following code works in aheatmap:
anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = FALSE)
levels(anno) = c("low activity", "medium activity", "high activity")
NMF::aheatmap(aaa,annCol=as.data.frame(anno))
But I get errors with this:
anno = factor(sample.int(3, size = 10, replace = TRUE), ordered = TRUE)
levels(anno) = c("low activity", "medium activity", "high activity")
NMF::aheatmap(aaa,annCol=as.data.frame(anno))
Error in Math.factor(c(1L, 3L), 0) : ‘round’ not meaningful for factors
In addition: Warning messages:
1: In if (class(annotation[[i]]) %in% c("character", "factor")) { :
the condition has length > 1 and only the first element will be used
2: In if (class(annotation[[i]]) %in% c("character", "factor")) { :
the condition has length > 1 and only the first element will be used
Interestingly, not the same error.
I have added a sensible error message to plotHeatmap and submitted the issue to NMF: renozao/NMF#83