ggtree
ggtree copied to clipboard
clade labels orientation problem with angle = "auto"
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.

> 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.

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).

Also here, I would like to ask for advice and/or any tips. Thank you!
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)

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

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

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.
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