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

Unaligned Tiles When Having a Circular Tree. #11

Closed
g-pacheco opened this issue Jul 1, 2021 · 2 comments
Closed

Unaligned Tiles When Having a Circular Tree. #11

g-pacheco opened this issue Jul 1, 2021 · 2 comments

Comments

@g-pacheco
Copy link

Hello everyone,

I fear that this might not be a real issue but since I have tried to solve it through different approaches to no avail, I am posting it here.

I have been using geom_fruit / geom_tile to create the tree below but the tiles are all unaligned. From the examples I have seen so far, they should be automatically aligned, so I am not quite sure it is going on. I reckon I am still missing an argument, but I could not figure out which one would it be.

# Creates base phylogeny ~
basePhylo2 <-
  ggtree(Data2, layout = "fan", aes(colour = group), size = .125) +
  scale_colour_manual(labels = c("Columba livia", "Columba rupestris"), values = c("#000000", "#fb8072"))

# Merges annotation to base phylogeny ~
basePhylo2_annot <- basePhylo2 %<+% Data2_annot

# Creates final phylo ~
basePhylo2_annot + 
  geom_fruit(
    geom = geom_tile,
    mapping = aes(y = label, x = BioStatus, fill = BioStatus),
    offset = .08,
    pwidth = .25)

Thanks in advance, George.

Screenshot (115)

@xiangpin
Copy link
Member

xiangpin commented Jul 3, 2021

This is because the x of geom_tile was mapped to the BioStatus. Since each tip belonged to a single BioStatus not multiple BioStatus. You can remove the x or set x to a single integer . You can refer to the following codes.

> library(ggtree)
> library(ggtreeExtra)
> set.seed(123)
> tr <- rtree(100)
> da <- data.frame(id=tr$tip.label, test=c(rep("A",25),rep("B",25),rep("C", 25), rep("D", 25)))
> p <- ggtree(tr, layout="circular") + geom_tiplab(align=TRUE)
> p <- p %<+% da
> p + geom_fruit(geom=geom_tile, mapping=aes(fill=test), width=0.8, offset=0.3)

test

Note: Since the x was not mapped in aes. Please use width to adjust the width of geom_tile layer instead of pwidth. You can also see the answer

@g-pacheco
Copy link
Author

Hello,

Thanks very much for your quick reply. You are absolutely right, and it does work as intended now!

Best regards, George.

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