help on drawing a tree with "ape"?

classic Classic list List threaded Threaded
8 messages Options
Hua
Reply | Threaded
Open this post in threaded view
|

help on drawing a tree with "ape"?

Hua
Dear all,

I'm using the "ape" package in R and want to draw a
phylogenetic tree with not only the tip labels but
also some labels for the edges. e.g. Mark the edge AB
as "m" in the tree ABC.  

Couldn't find a way to do that. Can someone help?

Thanks,

Hua

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Simon Blomberg-4
?edgelabels

On Sun, 2007-11-11 at 16:51 -0800, Hua Li wrote:

> Dear all,
>
> I'm using the "ape" package in R and want to draw a
> phylogenetic tree with not only the tip labels but
> also some labels for the edges. e.g. Mark the edge AB
> as "m" in the tree ABC.  
>
> Couldn't find a way to do that. Can someone help?
>
> Thanks,
>
> Hua
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Simon Blomberg, BSc (Hons), PhD, MAppStat.
Lecturer and Consultant Statistician
Faculty of Biological and Chemical Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer can
be extracted from a given body of data. - John Tukey.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hua
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Hua
Dear Simon and everyone,

Thanks for response.

Specifically, I have a tree with species "A, B, C" and
can be written as
"((A:45.15,C:45.15):46.19,B:91.34):0.0;" . If I use
the R command


> mytreeABC

[1] "((A:45.15,C:45.15):46.19,B:91.34):0.0;"

>     plot(read.tree(text = mytreeABC))

I would get a tree as shown in "Rresult.ps" file.
However, I would like the tree to show like in
"treeABC.jpg" file.

In case the r-hlep list do not allow attachment, here
is what Rresult.ps look like:

|-------------B
|
|
|      |------C
|------|
       |------A

for the tree I want (in treeABC.jpg), I would mark the
edge AC as "b", and the edge AB as "a".


Thank you very much for help!

Hua


--- Simon Blomberg <[hidden email]> wrote:

> ?edgelabels
>
> On Sun, 2007-11-11 at 16:51 -0800, Hua Li wrote:
> > Dear all,
> >
> > I'm using the "ape" package in R and want to draw
> a
> > phylogenetic tree with not only the tip labels but
> > also some labels for the edges. e.g. Mark the edge
> AB
> > as "m" in the tree ABC.  
> >
> > Couldn't find a way to do that. Can someone help?
> >
> > Thanks,
> >
> > Hua
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> --
> Simon Blomberg, BSc (Hons), PhD, MAppStat.
> Lecturer and Consultant Statistician
> Faculty of Biological and Chemical Sciences
> The University of Queensland
> St. Lucia Queensland 4072
> Australia
> Room 320 Goddard Building (8)
> T: +61 7 3365 2506
> email: S.Blomberg1_at_uq.edu.au
>
> Policies:
> 1.  I will NOT analyse your data for you.
> 2.  Your deadline is your problem.
>
> The combination of some data and an aching desire
> for
> an answer does not ensure that a reasonable answer
> can
> be extracted from a given body of data. - John
> Tukey.
>
>

__________________________________________________



______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Rresult.ps (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Ben Bolker

Hua Li wrote
Dear Simon and everyone,

Thanks for response.

Specifically, I have a tree with species "A, B, C" and
can be written as
"((A:45.15,C:45.15):46.19,B:91.34):0.0;" . If I use
the R command
> mytreeABC

[1] "((A:45.15,C:45.15):46.19,B:91.34):0.0;"

>     plot(read.tree(text = mytreeABC))

--- Simon Blomberg <s.blomberg1@uq.edu.au> wrote:

> ?edgelabels
>
   Did you look at the examples in the file suggested by Simon?
Unfortunately, the PS file but not the JPG came through in the
version I read.

  It seems to me you may want _node_ labels rather
than _edge_ labels?    See below ...

mytreeABC = "((A:45.15,C:45.15):46.19,B:91.34):0.0;"
t1 = read.tree(text=mytreeABC)
library(ape)
plot(t1)
edgelabels(1:4)
nodelabels(c("a","b"))
Hua
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Hua

Thank you very much for the help, Ben!

As a follow up, is there a way to specify the labels,
through the way the text is written, rather than
reading the edge positions from the graph? For
example,

mytree =
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"
plot(read.tree(text = mytree))
edgelabels(c("a-b","b","b-d","d","d","a"))

would give the graph I want. You may notice that if
set a = 91.84; b= 51.78; d= 24.6, the labels I put on
each edge is the corresponding lengths in variable
form.  The way I do it right now need me to first draw
the tree and then manually set the labels, and I
suppose there should be an easier way to get them by
reading the way the tree is written
("((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;")?


Sorry for my low level questions. Just started using
"ape" and research on phylogenetic trees.

Best wishes,

Hua





--- Ben Bolker <[hidden email]> wrote:

>
>
>
> Hua Li wrote:
> >
> > Dear Simon and everyone,
> >
> > Thanks for response.
> >
> > Specifically, I have a tree with species "A, B, C"
> and
> > can be written as
> > "((A:45.15,C:45.15):46.19,B:91.34):0.0;" . If I
> use
> > the R command
> >> mytreeABC
> >
> > [1] "((A:45.15,C:45.15):46.19,B:91.34):0.0;"
> >
> >>     plot(read.tree(text = mytreeABC))
> >
> > --- Simon Blomberg <[hidden email]> wrote:
> >
> >> ?edgelabels
> >>
> >
>
>    Did you look at the examples in the file
> suggested by Simon?
> Unfortunately, the PS file but not the JPG came
> through in the
> version I read.
>
>   It seems to me you may want _node_ labels rather
> than _edge_ labels?    See below ...
>
> mytreeABC = "((A:45.15,C:45.15):46.19,B:91.34):0.0;"
> t1 = read.tree(text=mytreeABC)
> library(ape)
> plot(t1)
> edgelabels(1:4)
> nodelabels(c("a","b"))
>
> --
> View this message in context:
>
http://www.nabble.com/help-on-drawing-a-tree-with-%22ape%22--tf4789546.html#a13711995

> Sent from the R help mailing list archive at
> Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Ben Bolker
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hua Li wrote:

> Thank you very much for the help, Ben!
>
> As a follow up, is there a way to specify the labels,
> through the way the text is written, rather than
> reading the edge positions from the graph? For
> example,
>
> mytree =
> "((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"
> plot(read.tree(text = mytree))
> edgelabels(c("a-b","b","b-d","d","d","a"))
>
> would give the graph I want. You may notice that if
> set a = 91.84; b= 51.78; d= 24.6, the labels I put on
> each edge is the corresponding lengths in variable
> form.  The way I do it right now need me to first draw
> the tree and then manually set the labels, and I
> suppose there should be an easier way to get them by
> reading the way the tree is written
> ("((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;")?
>
>
> Sorry for my low level questions. Just started using
> "ape" and research on phylogenetic trees.
>
> Best wishes,
>
> Hua
>

How about


library(ape)
mytree =
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"
t1 = read.tree(text = mytree)
plot(t1)
edgelabels(c("a-b","b","b-d","d","d","a"))
str(t1)
t1$edge.length
names(t1$edge.length)[c(2,4,6)]=c("b","d","a")
plot(t1)
edgelabels(c("a-b","b","b-d","d","d","a"),adj=c(0.5,1.25))
with(as.list(t1$edge.length),
     edgelabels(c(a-b,b,b-d,d,d,a),adj=c(0.5,-0.5),bg="lightblue"))

?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOao+c5UpGjwzenMRAq+xAJ4/FFxTaUXhco2ZSNU4xOHCHWhyQQCfYFV/
8ymnDHBrtFVDELiZrC2WQ+I=
=A1e3
-----END PGP SIGNATURE-----

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hua
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Hua
Thanks again, Ben.

Specifically my question should be;

If I know that I'll be using variables to represent
the distances between species:

a = AB
b = AC
d = CD

and I also know my tree can be written as
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"

is there a way to allow me mark the edges without
having to see the tree topology first, so that when I
use "edgelabels", the symbols and the order (
c("a-b","b","b-d","d","d","a") ) should be
automatically arranged other than being specified by
me. In other words, I don't want to be the one who
tells R the command
"edgelabels(c("a-b","b","b-d","d","d","a"))". I'd
rather a way R finds out itself. (for example, after
some calculation, R knows the edgelabes should be the
way specified above other than, say, c("a", "b", "c",
"a-b", "a-c", "b-c"). )

Thank you!

Hua





--- Ben Bolker <[hidden email]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hua Li wrote:
> > Thank you very much for the help, Ben!
> >
> > As a follow up, is there a way to specify the
> labels,
> > through the way the text is written, rather than
> > reading the edge positions from the graph? For
> > example,
> >
> > mytree =
> >
>
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"

> > plot(read.tree(text = mytree))
> > edgelabels(c("a-b","b","b-d","d","d","a"))
> >
> > would give the graph I want. You may notice that
> if
> > set a = 91.84; b= 51.78; d= 24.6, the labels I put
> on
> > each edge is the corresponding lengths in variable
> > form.  The way I do it right now need me to first
> draw
> > the tree and then manually set the labels, and I
> > suppose there should be an easier way to get them
> by
> > reading the way the tree is written
> >
>
("((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;")?

> >
> >
> > Sorry for my low level questions. Just started
> using
> > "ape" and research on phylogenetic trees.
> >
> > Best wishes,
> >
> > Hua
> >
>
> How about
>
>
> library(ape)
> mytree =
>
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"
> t1 = read.tree(text = mytree)
> plot(t1)
> edgelabels(c("a-b","b","b-d","d","d","a"))
> str(t1)
> t1$edge.length
> names(t1$edge.length)[c(2,4,6)]=c("b","d","a")
> plot(t1)
>
edgelabels(c("a-b","b","b-d","d","d","a"),adj=c(0.5,1.25))
> with(as.list(t1$edge.length),
>    
>
edgelabels(c(a-b,b,b-d,d,d,a),adj=c(0.5,-0.5),bg="lightblue"))
>
> ?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -
> http://enigmail.mozdev.org
>
>
iD8DBQFHOao+c5UpGjwzenMRAq+xAJ4/FFxTaUXhco2ZSNU4xOHCHWhyQQCfYFV/
> 8ymnDHBrtFVDELiZrC2WQ+I=
> =A1e3
> -----END PGP SIGNATURE-----
>



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help on drawing a tree with "ape"?

Ben Bolker

Hua Li wrote
Thanks again, Ben.

Specifically my question should be;

If I know that I'll be using variables to represent
the distances between species:

a = AB
b = AC
d = CD

and I also know my tree can be written as
"((A:51.78,(C:24.6,D:24.6):27.18):40.06,B:91.84):0.0;"

is there a way to allow me mark the edges without
having to see the tree topology first, so that when I
use "edgelabels", the symbols and the order (
c("a-b","b","b-d","d","d","a") ) should be
automatically arranged other than being specified by
me. In other words, I don't want to be the one who
tells R the command
"edgelabels(c("a-b","b","b-d","d","d","a"))". I'd
rather a way R finds out itself. (for example, after
some calculation, R knows the edgelabes should be the
way specified above other than, say, c("a", "b", "c",
"a-b", "a-c", "b-c"). )
  This is a little bit hard, I will have to think about it ...

install.packages("fortunes"); library(fortunes); fortune("Yoda")

  Ben