Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_tiplab2() is broken with custom coord_polar() settings #638

Open
willgearty opened this issue Oct 24, 2024 · 4 comments
Open

geom_tiplab2() is broken with custom coord_polar() settings #638

willgearty opened this issue Oct 24, 2024 · 4 comments

Comments

@willgearty
Copy link
Contributor

My understanding is that specifying ggtree(..., layout="circular") is essentially the same as this:

library(ggplot2)
library(ggtree)
library(ape)
data("chiroptera")
ggtree(chiroptera) +
    coord_polar(theta = "y", start = -pi/2, direction = -1) +
    scale_y_continuous(limits = c(0, NA), expand = expansion(0, 0.6))

Created on 2024-10-24 with reprex v2.1.1

Based on the code here:

} else if (object$layout == 'circular' || object$layout == "inward_circular") {
## refer to: https://github.com/GuangchuangYu/ggtree/issues/6
## and also have some space for tree scale (legend)
obj <- list(coord_polar(theta='y', start=-pi/2, -1, clip = 'off'),
scale_y_continuous(limits = c(0, NA), expand = expansion(0, 0.6))
)
if (object$layout == 'inward_circular') {
obj[[3]] <- scale_x_reverse(limits = object$xlim)
}

However, this hardcodes the starting and ending points of the phylogeny, which I would prefer to have on the left. So I've been playing around with changing the start and direction arguments in coord_polar(), which seems to work fine, until you try to add tip labels. For any values other than the defaults, geom_tiplab2() breaks. Here are some interesting examples:

library(ggplot2)
library(ggtree)
library(ape)
data("chiroptera")
ggtree(chiroptera) +
    coord_polar(theta = "y", start = pi/2, direction = -1) +
    scale_y_continuous(limits = c(0, NA), expand = expansion(0, 0.6)) +
    geom_tiplab2(size = 0.8)

Created on 2024-10-24 with reprex v2.1.1

library(ggplot2)
library(ggtree)
library(ape)
data("chiroptera")
ggtree(chiroptera) +
    coord_polar(theta = "y", start = -pi/2, direction = 1) +
    scale_y_continuous(limits = c(0, NA), expand = expansion(0, 0.6)) +
    geom_tiplab2(size = 0.8)

Created on 2024-10-24 with reprex v2.1.1

@willgearty
Copy link
Contributor Author

Note that I discovered this after an issue was raised for my deeptime package: willgearty/deeptime#72

@xiangpin
Copy link
Member

I recommend using rotate_tree since the internal function needs the layout of ggtree.

library(ggplot2)
library(ggtree)
library(ape)
data("chiroptera")
p1 <- ggtree(chiroptera, layout='circular')
p2 <- rotate_tree(p1, 135)
p2 + geom_tiplab(size=1)

image

@willgearty
Copy link
Contributor Author

willgearty commented Dec 17, 2024

Ah, that's an excellent function to know about, thanks! Any way we could get it to work with coord_radial() with different start and end arguments? I see that you can combine the open_tree() and rotate_tree() functions, but both of those use coordinate systems, making it hard for me to combine them with coord_geo_polar() or coord_geo_radial() from deeptime.

@willgearty
Copy link
Contributor Author

I've developed a new geom that works with all coordinate systems: https://williamgearty.com/deeptime/dev/reference/geom_text_phylo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants