YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/treedata-book/
821 stars 172 forks source link

Scale on the y-axis in a tree rotated with 'layout_dendrogram()' #584

Open gvaleman opened 11 months ago

gvaleman commented 11 months ago

I'm editing a time-scaled tree using ggtree. The dates are correctly adjusted when I apply the 'mrsd' command and 'theme_tree2()', but when I try to rotate the tree with 'layout_dendrogram()', the scale still remains on the x-axis with no dates. Is there a way to place the date scale on the y-axis in a tree rotated with 'layout_dendrogram()'?

# Code without layout_dendrogram()
ggtree(my_tree, mrsd='2022-12-31') %<+% 
  metadato_arbol + 
  geom_tippoint(size = 2) + 
  theme_tree2()

image

# Using layout_dendrogram()
ggtree(my_tree, mrsd='2022-12-31') %<+% 
  metadato_arbol + 
  geom_tippoint(size = 2) + 
  theme_tree2() + layout_dendrogram()

image

SamPassmore commented 6 months ago

I have the same problem (in #598).

This is my current workaround:

library(ape)
library(ggtree)
library(ggplot2)

n = 50
t = rcoal(n)

ggtree(t) + 
  layout_dendrogram() +
  theme(axis.ticks.y = element_line(),
        axis.line.y = element_line(),
        axis.text.y = element_text())

Although it doesn't seem to allow custom tip labels(e.g. 20k instead to 20000), for a reason I cannot figure out.