Plotting Christmas Tree

🎄 The Tree of Christmas Trees 🎄

Image credit: Google Image

I saw a figure of all potential Christmas tree 🎄 at 🐦 Polypompholyx’s Tweet.

It looks strange for my first impression. So I did a quick check from Open Tree. This looks much better!

See code below:


# install.packages("rotl")
# install.packages("ape")

#loading libraries
library("rotl") #for querying open tree database
library("ape") #for tree manipulation

#First I preapred a table for those potential **Christmas Trees** with first column is common names,a nd second column is the scientific names
# then we read in the table as a query list to the Open Tree

query <- read.csv("XsmasTree.csv", header=TRUE, sep=",", stringsAsFactors=FALSE, quote="")
# check what our table look like this

# query names and get ottid
species <- tnrs_match_names(names = query$Scientific_name_rept.)

# check results
# fix fuzzy match on row 16, then updated it 
new_species<- update(species, row_number=16, new_ott_id = 248313)

# checking object
species <- new_species
species.ottid <- ott_id(species)

# extracting the phylogeny summarized in the Open tree
tree <- tol_induced_subtree(ott_ids=species$ott_id, label_format = "name")

# make it looks good
tree <- ladderize(tree)
plot.phylo(tree, cex=0.8)

# rename the tree tip labels
query[[2]][16] <-  "Picea pungens" #remove one extra space
query[[2]] <- gsub(pattern="\\s", "_", query[[2]])

new_label <- paste0(tree$tip.label,"(", query[[1]][match(tree$tip.label, query[[2]])], ")")

new_tree <- tree
new_tree$tip.label <- new_label

#png("The Tree of Christams Tree.png")
#plot(new_tree, cex=0.7)

#write.tree(new_tree, "renamed_Xsmas_tree.tre")

#plot a prettier tree
plot.phylo(new_tree, edge.color = "dark green", edge.width = 2, tip.color = "red", 
           label.offset = 0.5, main="The Tree of Christmas Tree", col.main="red")
mtext("---source from Open Tree", col="dark green", 3)

Tree of Xsmas Trees
Tree of Xsmas Trees
❄️ 🎅 🌵 🔔 ☃️ 🌲