jokergoo / jokergoo.github.io

Personal website
https://jokergoo.github.io
4 stars 0 forks source link

2020/05/31/word-cloud-as-heatmap-annotation/ #2

Closed utterances-bot closed 2 years ago

utterances-bot commented 4 years ago

Word cloud as heatmap annotation - A Bioinformagician

https://jokergoo.github.io/2020/05/31/word-cloud-as-heatmap-annotation/

Paul-Yuchao-Dong commented 4 years ago

Really cool blog on stretching what is possible. I find the trick of using "Show/hide Output" button really neat, how do you achieve that with RMarkdown?

jokergoo commented 4 years ago

You can put the following code to the end of your R markdown file:


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
    $("pre").not(".r").prepend("<input class='switch_hljs' type='button' value='show/hide output' />");
    $(".switch_hljs").next().hide();
    $(".switch_hljs").click(function() {
        $(this).next().toggle();
    })
});
</script>

It adds a button before every non-r code block and switches the visibility of the next code block.

Paul-Yuchao-Dong commented 4 years ago

Many thanks! that is very clear!

nfancy commented 2 years ago

Hi, really nice package. I was wondering, how can I add the text annotation using anno_link instead of word cloud. So, for example if I want to add the actual pathways instead of the key words in the text box.

jokergoo commented 2 years ago

@nfancy First you need to install the newest version of simplifyEnrichment from GitHub.

Then try the following code:

mat = matrix(rnorm(100*10), nrow = 100)

term = lapply(letters[1:10], function(x) {
    data.frame(c("this is sentence 1", "this is sentence 2"), 1:2)
})
names(term) = letters[1:10]
Heatmap(mat, row_split = split, 
    right_annotation = rowAnnotation(wc = anno_word_cloud(split, term, add_new_line = TRUE, 
        value_range = c(1, 2), fontsize_range = c(10, 12)))
)

image

I have added some examples in the vignette. You can find in the bottom part of https://jokergoo.github.io/simplifyEnrichment/articles/word_cloud_anno.html

nfancy commented 2 years ago

Thank you very much for your solution.

hsiaoyi0504 commented 2 years ago

Is there a way to control the color of each sentences directly (rather than depending on font size)? Like I have a GSEA result and would like to put them in the right hand side of the heatmap by setting font size based on NES score and change colors based on p-value.

jokergoo commented 2 years ago

Then you may directly use anno_text_box(). Note this is a new function and I haven't written the documentation for it.

WandeRum commented 2 years ago

Thank you for implementing this nice feature which is super useful for biological data analysis. However, I've met problems using the same script on top as well as my own data. I found the annotation rows are not corresponding to the correcct rows but clumping to the upper-right part of the heatmap. I tested it on multiple computers which showed the same problem. Any potential reasons or solutions? Thank you!

jokergoo commented 2 years ago

@WandeRum are you using Rstudio? Did you see any message when you use the function? There must be some messages specifically for Rstudio to tell you want to do.