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

Tip label angle with radial plotting #72

Open
alexskeels opened this issue Oct 24, 2024 · 2 comments
Open

Tip label angle with radial plotting #72

alexskeels opened this issue Oct 24, 2024 · 2 comments

Comments

@alexskeels
Copy link

Attempting to plot tip labels with coord_geo_radial leads to interesting bevahiour. Looks like the labels remain pivoted on the fist letter rather than adjusting for the angle as is done when plotting a circular tree with ggtree.

`library(ape)
library(ggtree)
library(deeptime)
data("chiroptera")

Standard ggtree plot

revts(ggtree(chiroptera, layout="circular") +
geom_tiplab(size=0.8))

Standard ggtree plot with geom_tiplab2 (for circular layout)

revts(ggtree(chiroptera, layout="circular") +
geom_tiplab2(size=0.8))

with coord_geo_radial

revts(ggtree(chiroptera) +
coord_geo_radial( dat = "epochs", abbrv = T)+
geom_tiplab(size=0.8))

with coord_geo_radial - even whackier with geom_tiplab2

revts(ggtree(chiroptera) +
coord_geo_radial( dat = "epochs", abbrv = T)+
geom_tiplab2(size=0.8))`

@willgearty
Copy link
Owner

OK, after lots of experimenting, I've discovered that this appears to be an assumption within geom_tiplab2() that the start/end of the circular phylogeny is on the right side of the plot. So, in fact, using coord_geo_polar() with geom_tiplab2() works:

library(ggplot2)
library(ggtree)
library(deeptime)
library(ape)
data("chiroptera")
revts(ggtree(chiroptera) +
          coord_geo_polar(theta = "y") +
          geom_tiplab2(size=0.8))

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

You could change the y-scale to get a gap like in coord_geo_radial():

library(ggplot2)
library(ggtree)
library(deeptime)
library(ape)
data("chiroptera")
revts(ggtree(chiroptera) +
          coord_geo_polar("epochs") +
          scale_y_continuous(limits = c(0, NA), expand = expansion(0, c(0.6, 20))) +
          geom_tiplab2(size = 0.8))

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

But, we can go a step further and use coord_geo_radial() with just some minor tweaks stolen from coord_geo_polar() to make the phylogeny start and end on the right:

library(ggplot2)
library(ggtree)
library(deeptime)
library(ape)
data("chiroptera")
revts(ggtree(chiroptera) +
          coord_geo_radial("epochs", start = -pi/2, direction = -1) +
          geom_tiplab2(size = 0.8))

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

Tada!

@willgearty willgearty changed the title Tip label angl with radial plotting Tip label angle with radial plotting Oct 24, 2024
@willgearty
Copy link
Owner

I've reached out to the ggtree folks to see if we can get geom_tiplab2() to work with any fan phylogeny orientation.

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