Coder Social home page Coder Social logo

Comments (4)

ashenkin avatar ashenkin commented on May 29, 2024 1

This is great! Thanks so much. It seems to work. Here's an example of adding node colors too. I think this is a very nice step forward for your very nice package.

require(ggtree)

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)

ggtree(g2) + geom_tippoint(aes(color=I(color)))

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) + geom_tippoint(aes(color=I(color))) + geom_nodepoint(aes(size = randomTrait, color = I(color)))

rplot02

from ggtree.

GuangchuangYu avatar GuangchuangYu commented on May 29, 2024
require(phylobase)
require(ggtree)

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)

ggtree(g2) + geom_tippoint(aes(color=I(color)))

screenshot 2016-05-10 17 13 14

it was supported in ggtree >= 1.5.2

from ggtree.

GuangchuangYu avatar GuangchuangYu commented on May 29, 2024

thanks for your feedback 👍

from ggtree.

GuangchuangYu avatar GuangchuangYu commented on May 29, 2024

it can be done using %<+% operator to attach user's data.

require(ggtree)

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

p <- ggtree(g1) %<+% d + geom_tippoint(aes(color=I(color)))

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


p %<+% rNodeData  + geom_nodepoint(aes(size = randomTrait, color = I(color2)))

screenshot 2016-05-12 18 59 31

This phylo4d solution is a very good alternative.

In ggtree, we also provide another solution, that is to merge the newick tree text with user's data to a single jplace file and then parse the file in ggtree and visualize it with user's data.

from ggtree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.