Code Monkey home page Code Monkey logo

Comments (5)

jokergoo avatar jokergoo commented on May 16, 2024

Hi,

You can pass clusters to split options:

set.seed(12345)
mat = matrix(rnorm(100), nr = 25)

hr = hclust(dist(mat), method = "average")
clusters = dendextend::cutree(hr, k = 5)

Heatmap(mat, split = clusters)

from complexheatmap.

jokergoo avatar jokergoo commented on May 16, 2024

another way is to mark subtrees with different colors instead of splitting the heatmap

set.seed(12345)
mat = matrix(rnorm(100), nr = 25)

hr <- hclust(dist(mat), method = "average")
hr = as.dendrogram(hr)
clusters <- dendextend::cutree(hr, k = 5)

Heatmap(mat, name = "foo", cluster_rows = hr)

add_alpha = function(col, alpha = 0.5) {
    rgb(t(col2rgb(col)/255), alpha=alpha)
}
decorate_row_dend("foo", {
    ind = clusters[order.dendrogram(hr)]

    first_index = function(l) which(l)[1]
    last_index = function(l) { x = which(l); x[length(x)] }

    x1 = sapply(1:5, function(i) first_index(ind == i)) - 1
    x2 = sapply(1:5, function(i) last_index(ind == i))

    grid.rect(y = 1-x1/length(ind), height = (x2 - x1)/length(ind), just = "top",
        default.units = "npc", gp = gpar(fill = add_alpha(1:5, 0.2), col = NA))
})

test

from complexheatmap.

minisciencegirl avatar minisciencegirl commented on May 16, 2024

Thanks for the suggestion.

I think given that my matrix is quite large, I was hoping to split the tree into smaller subtree rather than highlighting the dendrogram with different colours.

Unfortunately when I tried passing the split = clusters to the Heatmap( ), I am now getting a different error: Error in object@row_dend_list[[k]] : subscript out of bounds

The toy dataset works for me - is there a limit to the size of dataframe that I can plot with Heatmap?

from complexheatmap.

jokergoo avatar jokergoo commented on May 16, 2024

Is it possible for you to send me the data matrix? I simulated a huge matrix and split into 100 pieces and it works fine.

On the other hand, why do you want to split rows into 100 parts? I think it is not a good way for visualization. (See following heatmap, the heatmap is split into 100 parts)

test

from complexheatmap.

minisciencegirl avatar minisciencegirl commented on May 16, 2024

Hmm I see what you meant. It doesn't really look that great.

Just sent you an email with the dataframe to your gmail.

from complexheatmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.