kingaa / ouch Goto Github PK
View Code? Open in Web Editor NEWOrnstein-Uhlenbeck models for phylogenetic comparative hypotheses
Home Page: http://kingaa.github.io/ouch/
License: GNU General Public License v3.0
Ornstein-Uhlenbeck models for phylogenetic comparative hypotheses
Home Page: http://kingaa.github.io/ouch/
License: GNU General Public License v3.0
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
#'
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
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
Line 54 in 3dec2ce
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")
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.
Marguerite
Problem plot: output from BEAST:
require(ouch)
require(ape)
atree <- read.nexus("consensus_beast.trees")
plot(atree, cex=.2, no.margin=T)
otree <- ape2ouch(atree)
plot(otree, cex=.2)
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.
Line 79 in 3dec2ce
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)
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.
Line 86 in d993a48
Could you please provide some guidelines on working with ouchtree objects?
I'm trying to loop on all internal nodes and determine the number of terminal nodes under each. How can this be achieved?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.