Giter Site home page Giter Site logo

kingaa / ouch Goto Github PK

View Code? Open in Web Editor NEW
15.0 6.0 4.0 1.57 MB

Ornstein-Uhlenbeck models for phylogenetic comparative hypotheses

Home Page: http://kingaa.github.io/ouch/

License: GNU General Public License v3.0

R 87.74% C 5.36% Makefile 6.91%
phylogenetic-comparative-hypotheses phylogenetic-data ornstein-uhlenbeck ornstein-uhlenbeck-models ouch react phylogenetic-comparative-methods brownian-motion adaptive-regime

ouch's People

Contributors

kingaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ouch's Issues

example for plot

Hi @kingaa
Here is a suggested example for the plot.R help page section for users on how to adjust label size.
Marguerite

#' @examples
#' data(bimac)
#' tree <- with(bimac,ouchtree(node,ancestor,time/max(time),species))
#' plot(tree, node.names=T)    # plot tree with node numbers
#' tree@nodelabels[!is.na(tree@nodelabels)]  <- paste("LongerSpeciesNames", 1:tree@nterm)
#' plot(tree)        # long species names are small
#' plot(tree, text_opts = list(cex=1.5), margin=c(0,.4))    # fix by increasing right margin and font size
#' 

Palette specification

Looks great Aaron! Thank you very much for your work. I think to make the palette customizable, though I think you need to put a conditional on this

ouch/R/plot.R

Line 54 in 3dec2ce

palette <- palette(length(levs))

 if (is.null(palette)) palette <- rainbow(length(levs))

Otherwise users will have to write a function to customize that takes as an argument the length of levels. I guess I was thinking that users could just specify a vector of colors. Something along the lines of c("reg1"="red", "reg2"="blue", "reg2="black")

Suggestions for plotting options

Some suggestions for plotting options that are better for large phylogenies or long taxon labels. We had a problem with not being able to read the metadata because it was cut off

https://github.com/kingaa/ouch/blob/master/R/plot.R#L17
Add frame.plot, cex, offset, rtspace arguments for tree.plot.internal:

# most users will not want the frame around the plot, but specifying it as part of ... generates a warning because itʻs not a valid argument to text() 
# the offset and rtspace is set to allow more space for taxon names (and at least show users what to change if need be)
# also changed the figure size to accommodate long taxon names
tree.plot.internal <- function (x, regimes = NULL, labels = x@nodelabels, legend = TRUE, frame.plot=F, cex=1, offset=0.1, rtspace=1, ...) {

More room for figure and Check size allotted to labels by character length:

    par(yaxt='n', mar=c(4, 1, 1, 1))
    plot(X,Y,type='l',col=C,xlab='time',ylab='',xlim=rx+c(-rxd,rtspace*rxd+max(strwidth(labels, units="figure"))),ylim=c(0,1), frame.plot=frame.plot,...)

And did you mean to include ... for text or only for plot? But if it is not a valid option it will throw a warning. The cex and offset are used here.

     text(X[seq(1,length(X),6)],Y[seq(1,length(Y),6)],labels[f],pos=4, cex=cex, offset=offset)

Also it would be really nice to be able to specify the pallette as an argument, but I am mulling over the best way to associate it with regime. - attach a regime name to the value?

These are small things, but really annoying when youʻre trying to get the figure right for publication.
Thank you!
Marguerite

plot.R.txt

Label Lengths and Margins

Thanks for your continued work on this! This is not really an issue but I tried it out on our large phylogeny and I wanted to show you what it looks like default as well as tweaked as best I could.

tree <- read.tree("beast_timecalibrated.tree")
otree <- ape2ouch(tree)
plot(otree)
plot(otree, text_opts=list(cex=2), margin=c(0,0.2))

I was trying to shift the entire plot to the left instead of leaving that large left margin, but all it does it cut off the tree (negative left margin). Not a big deal, but a little unexpected.

The plot labels on the default plot are super tiny! Might be shocking to naive users.

plot-extendedlabels.zip

ouch/R/plot.R

Line 86 in d993a48

xlim=rx+c(-1,1)*rxd,ylim=c(0,1),

Long labels

Hi Aaron,
This was actually the issue that really got me to hack the code. Real data exploration often involves long labels and if it is cut off, it can be a big problem to check if your regimes are correctly specified. This canʻt be fixed by making the text smaller sometimes because the region is set as a hard limit based on the node times

  rx <- range(x@times,na.rm=T)
  rxd <- 0.1*diff(rx)

In the phylogeny weʻre working on now, there are a lot of unnamed species (and long names). Sometimes we have to paste the names and sites together. We can write short codes, of course, for the species but the human brain can only process so much and with 250 taxa its really a problem.

ouch/R/plot.R

Line 79 in 3dec2ce

xlim=rx+c(-rxd,rxd),ylim=c(0,1),

My suggestion is to use the strwidth function to automatically size the plot region for the labels. This requires a cex= argument as cex is then passed to both the plot() and the text() functions. The other annoyance is that the x-axis labels then extends across the names too. I couldnʻt figure out how to limit that.

                xlim=rx+c(-rxd,rxd+max(strwidth(labels, units="figure", cex=cex))),

I generated these plots with the edits suggested and arguments

par(mar=c(2,0,0,0))
tree.plot.internal(ox, labels=labels, regimes=oreos, frame.plot=F, ladderize=F, legend=T, palette=c("black", "red", "pink", "green"), text_opts=list(pos=4, cex=.2), legend_opts=list(lwd=3, bty="n"), cex=.2)

namescut.pdf
namesok.pdf

Problem with plot? or ape2ouch?

I tested the plotting function with ape2ouch before submitting the patch, but I just tested it out on another format, and it plots OK in ape but not ouch. I really donʻt have any idea where to start with this one. Here is how to reproduce the issue

I have a large phylogeny, and the parenthesis output tree from IQTREE is fine in both, but the same plots from the ouput trees from BEAST (nexus format) plot fine in ape, but not ouch.
A smaller test nexus phylogeny works fine in both. So confused.

Here is a script and the inputs to reproduce the issue.

Archive.zip

Marguerite

Problem plot: output from BEAST:

require(ouch)
require(ape)

atree <- read.nexus("consensus_beast.trees")
plot(atree, cex=.2, no.margin=T)

ape plot OK:
Rplot_ape

otree <- ape2ouch(atree)
plot(otree, cex=.2)

ouch plot not OK:
Rplot_ouch

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.