This is really a programming question but ggtree
might be too obscure for this question to be posted on StackOverFlow as a general R related question.
I am having trouble extrapolating this this tutorial and the %<+%
operator in ggtree
.
I have a Newick file and a table that has a number for every tip and node in the Newick file. I want to produce a final graphic that shows a tree where the numbers from the table are shown next to respective tips and nodes.
What I want to do is close to the tutorial, I want to take a tree object and use a data-frame where one column is node-names and the second column holds numerical information per node. I want to attach the information from the data-frame to the tree object.
The data-frame looks something like this:
Node / tips | Count |
---|---|
A | 12 |
B | 14 |
So, I want to ultimately display the number 12 next to node A and number 14 next to node B while keeping the names intact. Now I have the code working up to the following point:
(I am really only just working my way through learning R's grammar of graphics and R in general, so assume I am doing something wrong.)
library(ggplot2)
library(ggtree)
x <- read.tree("tree.txt")
info <- read.csv("counts.csv",sep = '\t',header=TRUE)
p <- ggtree(x) %<+% info + xlim(-.1, 5)
p2 <- p + geom_tiplab(offset = 0.2) + geom_tippoint(aes(caption = Increase)) + theme_tree2()+geom_tiplab(align=TRUE, linesize=.5)+ xlim(0,25)
ggsave("test_2.pdf", width = 60, height = 80, units = "cm", limitsize = FALSE)
print(p2)
?geom_tippoint::aes() # is there a way to list all the option inside geom_tippoint::aes()
The above code overlays the Newick_label
column with the node names instead of attaching the value in the second column.
But specifically, I am at a loss as to how I can list the options available within geom_tippoint(aes())
. I can use ?geom_tippoint
to access the documentation of geom_tippoint
but I think my task needs to manipulate options within the aes()
function and the the geom_tippoint() documentation does not list all the aes()
options available. And am stuck trying different keywords for geom_tippoint(aes())
.
Can that be done in ggtree
or is this specific application of ggtree
obscure enough that there is no way to do this and produce a legible graphic? (eg issue: the graphic getting mushy overlays). I have hundred of (not uniform) genes trees so splitting data for each layer (node and tips) might be not the best way.
The files if anyone wants to try: counts and tree
Clarification on the labels for nodes and tips, I want to label both if possible. The data contains information for both.
Is annotating tips AND nodes out of the ordinary? Tips and nodes are technically different but I have quantitative data at both levels and am looking for the option to annotate at both levels.
geom_tiplab()
if I get the chance this week I will post a response on a hypothetical data set, but can't do this today. Oh wait, maybe not, there is still thetip
versusnode
issue - those are different solutions - might be easier just to copy part of the tree file to see what 'A' and 'B' are. At present the table is callednode/tips
: a tip is a subset of the nodes. $\endgroup$geom_tiplab()
for now, thanks! $\endgroup$