lazappi / clustree

Visualise Clusterings at Different Resolutions
https://lazappi.github.io/clustree/
GNU General Public License v3.0
215 stars 15 forks source link

Add argument to reverse tree #59

Open lazappi opened 4 years ago

lazappi commented 4 years ago

Currently clustree() and clustree_overlay() assume that higher values of the resolution variable will result in more clusters but this is not always the case and sometimes the reverse is true. For example:

image

We can reverse the appearance of the arrows by setting the edge_arrow_ends argument but this only changes the plot, not how things like the in proportion are calculated. The new argument should completely reverse the order of resolutions. This should be relatively simple to do by making sure sorting in done in the opposite order when required.

NadineBestard commented 2 years ago

If someone is looking for a workaround for this, waiting for the enhancement, here I suggest one that worked for me:

# save resolutions of interest with labels in decreasing order 
# now these new numbers will be used to compute the tree
sce$cluster_sorted_0 <- sce$cluster_k150
sce$cluster_sorted_1 <- sce$cluster_k120
sce$cluster_sorted_2 <- sce$cluster_k100
sce$cluster_sorted_3 <- sce$cluster_k80

# reassign each label to original value when plotting
tree_reverse <- clustree(sce, prefix = "cluster_sorted_") +
  scale_color_discrete(name="cluster_k", labels=c("150","120","100","80"))