Created
February 20, 2018 03:54
-
-
Save andersgs/82b3fd51f7d44bc87179d456805c60d6 to your computer and use it in GitHub Desktop.
Quick interactive phylogenetic tree in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LOAD LIBS --------------------------------------------------------------- | |
library(ape) | |
library(ggtree) | |
library(plotly) | |
# CREATE A TREE ------------------------------------------------------------- | |
n_samples <- 20 | |
n_grp <- 4 | |
tree <- ape::rtree(n = n_samples) | |
# CREATE SOME METADATA ---------------------------------------------------- | |
id <- tree$tip.label | |
set.seed(42) | |
grp <- sample(LETTERS[1:n_grp], size = n_samples, replace = T) | |
dat <- tibble::tibble(id = id, | |
grp = grp) | |
# PLOT THE TREE ----------------------------------------------------------- | |
p1 <- ggtree(tree) | |
metat <- p1$data %>% | |
dplyr::inner_join(dat, c('label' = 'id')) | |
p2 <- p1 + | |
geom_point(data = metat, | |
aes(x = x, | |
y = y, | |
colour = grp, | |
label = id)) | |
plotly::ggplotly(p2) |
I can not get the other layout options of ggtree to work properly. I get warnings and just part of the plot. Do you know how can I fix this?
I get an error with the aesthetic label: Warning: Ignoring unknown aesthetics: label
re @gotwals it seems as though the same general output can be achieved by switching to geom_text i.e.:
p2 <- p1 +
geom_text(data = metat,
aes(x = x,
y = y,
colour = grp,
label = id))
I don't know if you can see this, but this code works really well.
Is there any way to additionally display the bootstrap value or tip label as the ID of the sample rather than the group?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@teshu02 You can specify which aesthetics show when mousing over nodes by setting the
tooltip
parameter within theggplotly
function.Example using above snippet:
plotly::ggplotly(p2, tooltip = "label")