Closed theo-allnutt-bioinformatics closed 7 months ago
I can't access your Google drive; however, all the options of plotTree.barplot
in phytools are controlled either by par
or using args.plotTree
and args.barplot
. Try this reproducible example to see what I mean:
## load packages
library(phytools)
## load data
data("sunfish.data")
data("sunfish.tree")
head(sunfish.data)
gape.width<-setNames(sunfish.data$gape.width,rownames(sunfish.data))
## create plot
par(cex.axis=0.8)
plotTree.barplot(sunfish.tree,gape.width,
args.plotTree=list(fsize=0.8),
args.barplot=list(xlab="trait axis"))
Please let me know if you still can't figure out how to make the most out of this function. -- Liam
I have changed the sharing options - you should now be able to access the data. I have changed the axis font size, but the axis title font is unchanged. I still cannot change the large margin between the tree and the bars - see image attached.
pdf(file="bartree.pdf",width=50,height=130)
par(cex.axis=3)
plotTree.barplot(tree1,bardata,args.plotTree=list(fsize=3,ftype="reg",lwd=1),args.barplot=list(col="blue",space=1,xlab="genes@75%"))
dev.off()
Is there a manual / syntax for this function and it's options?
Thanks very much for your help.
ok.. I found par() lists the options. par(cex.lab=3) changed the axis label size.
From your reply on your blog: "Look at the help pages for phytools::plotTree and graphics::barplot for help identifying what the argument names for each object should be. -- Liam" I cannot find the help pages mentioned. Still can't work out how to reduce the gap. Do you have a link? Thanks.
I found this.. is this the right page? https://www.rdocumentation.org/packages/phytools/versions/2.0-3
Dear Theo.
Maybe try working with the following code. It uses phytools but not plotTree.barplot
.
library(phytools)
fam_tree<-read.tree(file="family_test.tre")
fam_genes<-read.table(file="famgenes75.txt",header=FALSE)
genes<-setNames(fam_genes[[2]],fam_genes[[1]])[fam_tree$tip.label]
png(file="example-plotTree.barplot.png",width=10,height=15,units="in",res=300)
par(mfrow=c(1,2))
plotTree(force.ultrametric(fam_tree,method="extend"),fsize=0.4,lwd=1,
color="transparent",mar=c(5.1,1.1,1.1,0))
pp<-get("last_plot.phylo",envir=.PlotPhyloEnv)
plotTree(fam_tree,ftype="off",xlim=pp$x.lim,add=TRUE,lwd=1,mar=c(5.1,1.1,1.1,0))
qq<-get("last_plot.phylo",envir=.PlotPhyloEnv)
for(i in 1:Ntip(fam_tree))
lines(c(pp$xx[i],qq$xx[i]),rep(pp$yy[i],2),lty="dotted",lwd=1,col="blue")
par(mar=c(5.1,0,1.1,1.1))
barplot(genes,horiz=TRUE,border=palette()[2],col=palette()[2],
names.arg="")
dev.off()
Here is the figure I obtained.
I would love to use this example on my blog. Please let me know if it would be OK to post this solution there @theo-allnutt-bioinformatics.
PS. The reason there is such a large space between the tree & barplot in plotTree.barplot
is because that function calculates the amount of horizontal space for the tree based on the total tree height & the maximum width of any tip label. Since your tree is non-ultrametric and the longest label is on a tip that is quite "shallow," the function leaves to much white space to the right of the tree. In this solution I line up the labels & then added linking lines from the tips on the plotted tree to each label, which I think is also more aesthetic. Saludos, Liam
Hi, thanks, I will try your solution. Yes you can use the plot but please change / remove the tip names. Can you point to the help pages anyway? Theo
The arguments taken by arg.barplot
and args.plotTree
are the majority (but not all, due to the constraint of the plot type) of the arguments taken by graphics::barplot
and phytools::plotTree
, respectively. To see each of these two help pages, with phytools loaded, just run ?barplot
or ?plotTree
at the command prompt of your interactive R session. -- LIam
Hi,
example of code: pdf(file="bartree.pdf",width=50,height=130)
plotTree.barplot(tree1,bardata,args.plotTree=list(fsize=3,ftype="reg",lwd=1),list(col="blue",space=1,xlab="genes@75%"))
dev.off()
How can the scale bar font size be altered? It is much smaller than tree labels. Also the figure has a very large gap between tree and bars. Is there a way to reduce it?
Thanks.
Data: https://drive.google.com/drive/folders/1kxyo8YIHRaXkukPNXRK-f298gQrOOx_D?usp=drive_link