New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom edge colouring #76

Closed
brj1 opened this Issue Oct 4, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@brj1
Contributor

brj1 commented Oct 4, 2016

According to the vignette on bioconductor.org, ggtree supports custom annotation, and thus custom colouring, of tips/nodes via the "%<+%" operator. It would be nice to have the same capability for custom edge colouring.

Thanks.

@GuangchuangYu

This comment has been minimized.

Show comment
Hide comment
@GuangchuangYu

GuangchuangYu Oct 5, 2016

Owner

You can use phylo4d:

require(ggtree)
require(phylobase)

set.seed(123)
tr = rtree(30)
g1 = as(tr, 'phylo4')
d = data.frame(color=sample(c('red', 'blue', 'green'), 30, replace=T))
rownames(d) = tr$tip.label
g2 = phylo4d(g1, d)

rNodeData <- data.frame(randomTrait = rnorm(nNodes(g1)),
                        color = sample(c('purple', 'yellow', 'black'), nNodes(g1), replace=T),
                        row.names = nodeId(g1, "internal"))

nodeData(g2) <- rNodeData
ggtree(g2, aes(color=I(color)))

Using %<+% is also possible:

require(ggtree)

set.seed(123)
tr = rtree(30)

d = data.frame(node=1:59, color=sample(c('red', 'blue', 'green'), 59, replace=T))
ggplot(tr) %<+% d + geom_tree(aes(color=I(color))) + theme_tree()

You may also find my post useful if you want to use your own data to annotate edges.

Owner

GuangchuangYu commented Oct 5, 2016

You can use phylo4d:

require(ggtree)
require(phylobase)

set.seed(123)
tr = rtree(30)
g1 = as(tr, 'phylo4')
d = data.frame(color=sample(c('red', 'blue', 'green'), 30, replace=T))
rownames(d) = tr$tip.label
g2 = phylo4d(g1, d)

rNodeData <- data.frame(randomTrait = rnorm(nNodes(g1)),
                        color = sample(c('purple', 'yellow', 'black'), nNodes(g1), replace=T),
                        row.names = nodeId(g1, "internal"))

nodeData(g2) <- rNodeData
ggtree(g2, aes(color=I(color)))

Using %<+% is also possible:

require(ggtree)

set.seed(123)
tr = rtree(30)

d = data.frame(node=1:59, color=sample(c('red', 'blue', 'green'), 59, replace=T))
ggplot(tr) %<+% d + geom_tree(aes(color=I(color))) + theme_tree()

You may also find my post useful if you want to use your own data to annotate edges.

@bmaitner

This comment has been minimized.

Show comment
Hide comment
@bmaitner

bmaitner Jun 13, 2018

In the examples provided, the user is directed to supply a set of values for each node, as is done with plotBranchbyTrait(tree, x, mode="nodes"). Is there a way to instead supply a vector of edge lengths directly, equivalent to plotBranchbyTrait(tree, x, mode="edges")?

bmaitner commented Jun 13, 2018

In the examples provided, the user is directed to supply a set of values for each node, as is done with plotBranchbyTrait(tree, x, mode="nodes"). Is there a way to instead supply a vector of edge lengths directly, equivalent to plotBranchbyTrait(tree, x, mode="edges")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment