Using R How would you create a random tree with 5 tips and save it in an object
ID: 3574954 • Letter: U
Question
Using R
How would you create a random tree with 5 tips and save it in an object called "Myrandomtree"?
B. How would you plot the tree you just made ?
C. How would you create a vector with the names of 5 colors in it? Name the vector "Mycolors."
D. To add large colored tips to your ggtree plot, you use the ggtree function and then add a line that looks like this. "+geom_tippoint(color=vectorofcolors, size=10)"
Now write the code here that makes the ggtree plot, and adds colored tips with the colors in your vector Mycolors. I also want you to make the size of the tips 2x larger than in my example.
Explanation / Answer
library("ape")
tree <- read.tree("tree.mod")
tree$edge
# [,1] [,2]
#[1,] 5 6 # root -> a:b
#[2,] 6 1 # == "a"
#[3,] 6 2 # == "b"
#[4,] 5 7 # root -> c:d
#[5,] 7 3 # == "c"
#[6,] 7 4 # == "d"
cols <- rep(c("blue", "red"), each=3)
plot.phylo(tree, edge.col=cols)
[Inline image 1]
ntips <- length(tree$tip.label)
cols <- c(rainbow(ntips), rep("black", nrow(tree$edge)-ntips+1))
plot.phylo(tree, edge.col=cols[tree$edge[,2]])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.