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

facet_plot will not plot correctly align to branch in ggtree #604

Open
cms72 opened this issue Feb 22, 2024 · 0 comments
Open

facet_plot will not plot correctly align to branch in ggtree #604

cms72 opened this issue Feb 22, 2024 · 0 comments

Comments

@cms72
Copy link

cms72 commented Feb 22, 2024

Hi - I have a set of descriptions (descriptons1) that I am trying to align to the tree. To separate these descriptions from another set of data, I used facet_plot. However, descriptions1 did not align to the branch - there were only two branches that contained description1

However, I did find that when there were > 5 branches with descriptions (see descriptions2), facet_plot worked.

Tree:
ggtree.newick.txt

######## Descriptions 1 and 2 ########
description1 <- data.frame (ID  = c("978", "978", "978","978", "978","974","974","974","974","974","974","974","974"),
                            Type = c("value_A", "value_B", "value_C","value_D", "value_E", "value_F","value_G", "value_H", "value_I","value_J", "value_K", "value_L","value_M"),
                            Desc = c("Blue","Pink","Red","White","Green","Purple","Yellow","Orange","Brown","Blue","Green","Green","Green"),
                            xindex= c(1,2,3,4,5,6,7,8,9,10,11,12,13)
)

description2 <- data.frame (ID  = c("978", "978", "978","978", "978","974","974","974","974","974","974","974","974","374", "374", "374","374", "374","372", "372", "372","372", "372","3", "3", "3","3", "3"),
                            Type = c("value_A", "value_B", "value_C","value_D", "value_E", "value_F","value_G", "value_H", "value_I","value_J", "value_K", "value_L","value_M","value_A", "value_B", "value_C","value_D", "value_E","value_A", "value_B", "value_C","value_D", "value_E","value_A", "value_B", "value_C","value_D", "value_E"),
                            Desc = c("Blue","Pink","Red","White","Green","Purple","Yellow","Orange","Brown","Blue","Green","Green","Green","Blue","Pink","Red","White","Green","Blue","Pink","Red","White","Green","Blue","Pink","Red","White","Green"),
                            xindex= c(1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
)

######## Tree ########
ggtree<-read.tree("ggtree.newick.txt")
midpoint_ggtree<-midpoint.root(ggtree)
tree1 <- ggtree(midpoint_ggtree) + geom_tiplab(size=2)

tree2 <- facet_plot(tree1, panel = "Description1", data = description1, geom=geom_tile, mapping = aes(x=xindex, y=y, fill = Desc),size=1)+
  scale_fill_brewer(palette="Set1", na.value="transparent", direction=-1,name="Description1")

tree3 <- tree2 + new_scale_fill()

tree3 <- facet_plot(tree2, panel = "Description2", data = description2, geom=geom_tile, mapping = aes(x=xindex, y=y, fill = Desc),size=1)+
  scale_fill_brewer(palette="Set1", na.value="transparent", direction=-1,name="Description2")

tree3
@cms72 cms72 changed the title facet_plot will not plot correctly against ggtree facet_plot will not plot correctly align to branch in ggtree Feb 22, 2024
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

1 participant