## A random tree
tree <- rtree(20)
## A random vector of two variables for each tips
tip_values <- sample(c("blue", "red"), 20, replace = TRUE)
## Matching the colors (blue and red) to the tips descendants
edge_colors <- match.tip.edge(tip_values, tree, replace.na = "grey")
## Plotting the results
plot(tree, show.tip.label = FALSE, edge.color = edge_colors)
tiplabels(1:20, bg = tip_values)
## Same but without assuming parsimony for the internal nodes
plot(tree, show.tip.label = FALSE,
edge.color = match.tip.edge(tip_values, tree,
use.parsimony = FALSE,
replace.na = "grey"))
## Matching the tips and nodes colors with the edges
node_values <- sample(c("blue", "red"), 19, replace = TRUE)
edge_colors <- match.tip.edge(c(tip_values, node_values), tree)
plot(tree, show.tip.label = FALSE, edge.color = edge_colors)
tiplabels(1:20, bg = tip_values)
nodelabels(1:19, bg = node_values)
Run the code above in your browser using DataLab