ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

clade labels orientation problem with angle = "auto"

Open FelixErnst opened this issue 4 years ago • 3 comments
trafficstars

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!

FelixErnst avatar Feb 15 '21 12:02 FelixErnst

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

xiangpin avatar Feb 22 '21 11:02 xiangpin

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.

FelixErnst avatar Feb 22 '21 12:02 FelixErnst

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

  • default is orient = -1 : the way angles are handled is untouched
  • orient = -2 is what I was looking for : all labels have their top going to the middle
  • orient = -3 is the same but with the bottom
  • orient = 0 or greater : same orientation for everybody, according to the number given

niebbiko avatar Oct 29 '23 21:10 niebbiko