Search code examples
rheatmapseurat

DoHeatmap function Seurat - Error in dataframe: arguments imply differing number of rows


I'm trying to use the DoHeatmap function in Seurat to show expression of a number of genes across some defined clusters. B_cells is my Seurat object.

tfs <- c("PRDM1", "PAX5", "BACH2")

DoHeatmap(B_cells, features=tfs)

I'm getting this error back;

Error in data.frame(group = sort(x = group.use), x = x.divs) : 
  arguments imply differing number of rows: 10411, 0

When I look at the number of rows and columns in the Seurat object;

nrow(B_cells) = 19651

ncol(B_cells) = 10151

Sorry if this is a silly question but I've been stuck on it for a while now.

edit traceback():

3: stop(gettextf("arguments imply differing number of rows: %s", 
       paste(unique(nrows), collapse = ", ")), domain = NA)
2: data.frame(group = sort(x = group.use), x = x.divs)
1: DoHeatmap(B_cells, features = genes)

Solution

  • The source code for the DoHeatmap() function can be found at https://github.com/satijalab/seurat/blob/develop/R/visualization.R. The traceback() shows line 363 of visualization.R is causing the error:

    if (label) {
       x.max <- max(pbuild$layout$panel_params[[1]]$x.range)
       # Attempt to pull xdivs from x.major in ggplot2 < 3.3.0; if NULL, pull from the >= 3.3.0 slot
       x.divs <- pbuild$layout$panel_params[[1]]$x.major %||% pbuild$layout$panel_params[[1]]$x$break_positions()
       x <- data.frame(group = sort(x = group.use), x = x.divs)
       ...
    }       
    

    As a workaround to bypass the error try:

    DoHeatmap(B_cells, features=tfs, label=FALSE)