Closed TimJCooper closed 4 years ago
I'm having the same issue now and can't figure out why it won't work. Would you mind posting an update to cover how you resolved the issue? Other sources I can find online all recommend ensuring that row names for the annotation and the matrix are equal to one another, but even after doing that, I'm getting the exact same error message.
@raivokolde Any chance of an update on this?
Here a reprex:
dta <- iris[, 1:4]
annotation <- iris[, "Species", drop = FALSE]
randoid <- rownames(iris)
pheatmap::pheatmap(
mat = dta,
annotation_row = annotation,
labels_row = randoid
)
#> Error in annotation_colors[[colnames(annotation)[i]]] :
#> subscript out of bounds
pheatmap::pheatmap(
mat = dta[rownames(dta), ],
annotation_row = annotation,
labels_row = randoid
)
The problem here is that the pheatmap expects a matrix with row and column names as an input. Here, it is a data.frame instead. It will be converted to a matrix internally, but for some reason as.matrix(dta[rownames(dta), ])
has rownames and as.matrix(dta)
doesn't. Not sure how to adjust the pheatmap code to avoid this problem though.
Two choices,
data.frame
and ensure the provided matrix has row names.as.matrix
S3 method for objects that inherits from data.frame
(i.e., inherits(mat, "data.frame")
) and the "rownames.force" argument: as.matrix(iris, rownames.force = TRUE)
Test dataset: https://www.dropbox.com/s/hy56owg4mfjuxol/Test_Data.RData?dl=0 Plotting this dataset runs as expected:
pheatmap(t(pred.MDSC$scores), fontsize=8)
However, if I then attempt to add annotation to it:It returns the error:
Is this a bug, or am I doing something wrong with the annotation data structure?