YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
839 stars 173 forks source link

clade labels orientation problem with angle = "auto" #378

Open FelixErnst opened 3 years ago

FelixErnst commented 3 years ago

Hi,

I have a problem plotting clade labels. They seem to oriented inverted, if I plot them using angle = "auto"

> library(ggtree)
> library(ape)
> x <- rtree(20)
> p <- ggtree(x, layout="circular") + 
+     geom_cladelab(mapping = aes(subset = TRUE, node = node, label = label), offset.text = 1) + 
+     geom_tiplab(mapping = aes(label = label))
Warning message:
Removed 19 rows containing missing values (geom_text). 

The default plot looks good. image

> p <- ggtree(x, layout="circular") + 
+     geom_cladelab(mapping = aes(subset = TRUE, node = node, label = label), offset.text = 1, angle = "auto") + 
+     geom_tiplab(mapping = aes(label = label))
Warning message:
Removed 19 rows containing missing values (geom_text). 

The clade labels are not oriented correctly. Sometimes they are correct and sometimes they are inverted. image

In addition, the labels of clades are not adjusted, when using rotate_tree. The move around correctly, but the orientation is not changed.

> rotate_tree(p, 90)
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
Warning message:
Removed 19 rows containing missing values (geom_text). 

image

Also here, I would like to ask for advice and/or any tips. Thank you!

xiangpin commented 3 years ago

If you use circular layout, you can specify horizontal=FALSE and angle="auto" to show the labels. You can refer the following codes.

library(ggtree)
library(ape)
library(patchwork)

set.seed(1024)

x <- rtree(20)
p <- ggtree(x, layout="circular") +
     geom_tiplab(mapping = aes(label = label))

p1 <- p +
     geom_cladelab(mapping = aes(subset = TRUE, node = node, label = label),
                   offset.text = 1.5,
                   barcolor = NA)

label_angle1


p2 <- p +
      geom_cladelab(mapping = aes(subset = TRUE, node = node, label = label),
                   offset.text = 1.5,
                   barcolor = NA,
                   horizontal=FALSE)

label_angle2

p3 <- p +
      geom_cladelab(mapping = aes(subset = TRUE, node = node, label = label),
                   offset.text = 1.5,
                   barcolor = NA,
                   horizontal=FALSE,
                   angle = "auto")

label_angle3

FelixErnst commented 3 years ago

Thanks for your answer. However, the issue remains. When using angle = "auto" and horizontal = TRUE the left hand site labels are shown upside down.

I know, that this problem is eleviated by setting horizontal = FALSE, but in combination with rotate the orientation will end up wrong. See my second and third image.

niebbiko commented 1 year ago

orient_option.patch.txt at least for tips, I think that a patch like the one provided could help