yulab-smu / ggtree Goto Github PK
View Code? Open in Web Editor NEW:christmas_tree:Visualization and annotation of phylogenetic trees
Home Page: https://yulab-smu.top/treedata-book/
:christmas_tree:Visualization and annotation of phylogenetic trees
Home Page: https://yulab-smu.top/treedata-book/
clade
is an important concept in phylogenetic tree. We may want to export a selected clade in a very large tree via gzoom function, which works in tree object. If we want to zoom in selected clade of a tree view that was already annotated with ggtree, it's not possible to use with gzoom
.
Instead of providing another similar function that works with tree view, I think it would be more flexible to provide the clade position containing xmin
, xmax
, ymin
and ymax
. So that user can zoom in the clade by restricting the coordination system to the selected area.
require(ggplot2)
require(ggtree)
p = ggtree(rtree(30)) + geom_tippoint()
cpos = get_clade_position(p, node=45)
p2 = with(cpos, p+xlim(xmin, xmax)+ylim(ymin, ymax))
print(p2+ ggtitle("zoom in selected clade"))
Then we can put them together side by side, just like gzoom
.
p1 = p + geom_hilight(node=45)
require(gridExtra)
grid.arrange(p1, p2, ncol=2)
And more flexible to embed tree view using subview function.
with(cpos, subview(p2, p1+theme_transparent(), x=xmin+(xmax-xmin)*.2, y=ymin+(ymax-ymin)*.8))
With the position information, user can annotate clade using geom_segment
and geom_text
, it will be more flexible than annotation_clade
to tune detail.
with(cpos, p1 + geom_segment(x=xmax + .1, xend=xmax+.1, y=ymin, yend=ymax) +
geom_text(x=xmax+.2, y=(ymin+ymax)/2, label='clade text', hjust=0) + xlim(NA, 7))
Hi there,
Really liking ggtree - thanks so much for a great tool. One question - have you considered supporting phylo4d objects? Seems like it would be a natural fit for ggtree. As it stands, I seem to have to use data outside of aes() clauses for things like geom_tippoint, as it looks for an object with rows = # of nodes (not just number of tips). Additionally, I have to be wary of the ordering of data matching that of the ordering of the tips of the original tree, etc.
phylo4d, i think, was created to solve these issues. Perhaps there are other ways of going about this that solve these issues without phylo4d... Any thoughts much appreciated. Thanks!
me again,
if you add a scale_y_continuous
after the current line 61 in ggtree, we can have non overlapping branches for those two coord_polar
-ized layouts
eg:
p <- p + scale_y_continuous(limits=c(0, sum(p$data$isTip)))
Is it possible to ladderize in the other direction (increasing or decreasing order)?
Thanks!
library(ggtree)
set.seed(123)
tree=rtree(30)
tree=groupClade(tree, 34)
df=fortify(tree)
ggplot(df, aes(color=x)) + geom_tree2()
Mapping color to continuous variable is OK.
But if I try mapping to categorical variable, it won't work.
ggplot(df, aes(color=group)) + geom_tree2()
The data has no problem.
> head(df)
node parent branch.length x y label isTip branch angle group
1 1 35 0.7989248 2.410756 4 t10 TRUE 2.011294 42 1
2 2 35 0.1218993 1.733731 5 t28 TRUE 1.672781 30 1
3 3 34 0.5609480 1.730580 3 t25 TRUE 1.450106 60 1
4 4 37 0.7533079 2.211171 7 t19 TRUE 1.834517 6 0
5 5 38 0.3744628 2.727372 8 t17 TRUE 2.540140 -6 0
6 6 38 0.6651152 3.018024 9 t29 TRUE 2.685466 -18 0
and it works with original implementation, geom_tree()
.
ggplot(df, aes(color=group)) + geom_tree()
source code: https://github.com/GuangchuangYu/ggtree/blob/master/R/geom_tree.R
I keep getting the same error when trying to collapse the tree saying that the node is a tip, even when it isn't. Below is an example using the test file from the vignette.
nwk <- system.file("extdata", "sample.nwk", package="ggtree")
tree <- read.tree(nwk)
ggtree(tree) + geom_text(aes(label=node))
ggtree(tree) + geom_text(aes(label=node)) %>% collapse(node=21)
Error in get.offspring.df(df, node) : input node is a tip...
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggtree_1.0.21 ggplot2_1.0.1 knitr_1.11 phytools_0.5-00 maps_3.0.0-2 ape_3.3 readr_0.2.2
loaded via a namespace (and not attached):
[1] phangorn_1.99.14 locfit_1.5-9.1 reshape2_1.4.1 splines_3.2.2
[5] lattice_0.20-33 colorspace_1.2-6 expm_0.999-0 stats4_3.2.2
[9] survival_2.38-3 EBImage_4.10.1 BiocGenerics_0.14.0 jpeg_0.1-8
[13] plyr_1.8.3 stringr_1.0.0 zlibbioc_1.14.0 Biostrings_2.36.4
[17] munsell_0.4.2 gtable_0.1.2 mvtnorm_1.0-3 labeling_0.3
[21] IRanges_2.2.9 parallel_3.2.2 proto_0.3-10 Rcpp_0.12.1
[25] scales_0.3.0 plotrix_3.6 clusterGeneration_1.3.4 S4Vectors_0.6.6
[29] scatterplot3d_0.3-36 jsonlite_0.9.17 XVector_0.8.0 abind_1.4-3
[33] gridExtra_2.0.0 mnormt_1.5-3 png_0.1-7 digest_0.6.8
[37] stringi_1.0-1 tiff_0.1-5 msm_1.5 animation_2.4
[41] numDeriv_2014.2-1 grid_3.2.2 quadprog_1.5-5 tools_3.2.2
[45] magrittr_1.5 MASS_7.3-44 Matrix_1.2-2 nnls_1.4
[49] rstudioapi_0.3.1 fftwtools_0.9-7 igraph_1.0.1 nlme_3.1-122
Hi there. Really like this package. I have being trying to figure out if the subview function can be used to annotate nodes with small pie charts based on an ancestral character reconstruction. This type of node label is possible using the ape function node label(pie = results), where results is a matrix with state probabilities at each node.
This would be a great feature to add if it is not already possible with subview!
cls <- list(c1=c("A", "B", "C", "D", "E"),
c2=c("F", "G", "H"),
c3=c("L", "K", "I", "J"),
c4="M")
tree <- groupOTU(tree, cls)
library("colorspace")
ggtree(tree, aes(color=group, linetype=group)) + geom_text(aes(label=label), hjust=-.25) +
scale_color_manual(values=c("black", rainbow_hcl(4))) + theme(legend.position="right")
works well. However, I wanna to design the color for each group, how shall I designate color for each group?
eg: i wanna all the blue color in following group goes to gray.
> phytree
Phylogenetic tree with 74 tips and 73 internal nodes.
Tip labels:
Sal_JR3_62_z4_z23_RSK2980, Sal_JR3_62_z36_RKS2983, Sal_JGG_CFSAN001992, Sal_JBX_CFSAN001080, Sal_JM6_CVM19633, Sal_JIX_507440_20, ...
Rooted; includes branch lengths.
## bttree is output from 'ape::boot.phylo'
> bttree
[1] 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 80 78
[20] 86 100 73 100 100 100 100 100 79 100 85 100 100 100 100 100 100 100 100
[39] 100 100 100 100 100 99 89 100 94 100 100 73 39 100 100 100 100 100 89
[58] 100 100 73 70 67 97 94 100 74 100 63 46 100 100 89 98
> require(ggtree)
> x <- apeBoot(phytree, bttree)
> x
'apeBoot' S4 object that stored bootstrap value generated by 'ape::boot.phylo' .
...@ tree:
Phylogenetic tree with 74 tips and 73 internal nodes.
Tip labels:
Sal_JR3_62_z4_z23_RSK2980, Sal_JR3_62_z36_RKS2983, Sal_JGG_CFSAN001992, Sal_JBX_CFSAN001080, Sal_JM6_CVM19633, Sal_JIX_507440_20, ...
Rooted; includes branch lengths.
> ggtree(x) + geom_label(aes(label=bootstrap))
Hello, thank you for your useful package! It really helps me in visualization of my complex data sets associated with tree!
I often use the visualization tree with associated matrix functionality. But I have some ordinary issues.
I wonder if it is possible to:
I will be very greatful for this new features!
Hi,yu
my trouble is when I groupout my tree some clades are broken like this,I don't know how to deal with this trouble!as follow
code is
ggtree(tree, aes(color=group),branch.length="none", layout = "circular", size = 0.5)
But if I cant't groupOUT the tree it's normal,view tree as follow
code is
ggtree(tree, branch.length = "none", layout = "circular", size = 0.5)
Do you kown what's wrong with me?
Hi Guangchuang,
Thanks for introducing such a nice R package.
I was importing a codeml file. Everything works fine except the tips did not display properly, as the screen shot shows, the tip names were chopped. Am I missing something?
ggtree(mlc, branch.length="none") + geom_text2(aes(subset=!isTip, label=node), hjust=-.3) + geom_tiplab()
Best,
Mao-Lun
Highlighting multiple clades in a phylogram works fine,
ggtree(tree) %>% hilight(node=134,fill="slategray2",alpha=0.6) %>% hilight(node=82,fill="chocolate2",alpha=0.6) %>% hilight(node=91,fill="darkgoldenrod2",alpha=0.6) ... + geom_text(aes(label=node), size=2, color="purple", hjust=-.2, na.rm = T)
but when I change the layout type to circular, it will not highlight the same clades
ggtree(tree, layout="circular") %>% hilight(node=134,fill="slategray2",alpha=0.6) %>% hilight(node=82,fill="chocolate2",alpha=0.6) %>% hilight(node=91,fill="darkgoldenrod2",alpha=0.6) ... + geom_text(aes(label=node), size=2, color="purple", hjust=-.2, na.rm = T)
Perhaps a problem with my Newick formatting? Strange that it works on phylogram.
Hello,
I like the flexibility of the package and the ability to work with phylogenetic trees in a graphics oriented way. I think it could be made even better if you could control the display parameters for node labels the way ggtree allows for tip labels. This could include trees passed from other packages. I pruned taxa from a RAxML tree with drop.tip {ape} and labeled clades with ggtree. I would love to exclude values for clades receiving bootstrap values less than 70 percent (or any value...) and move these values to the middle of their branches, leaving the taxa at the tips. I am not expert at R, but I couldn't find an easy way to hack a solution to any of these issues. Still, nice package. I hope it continues to be developed.
Ryan
I am having trouble formatting the names in the circular tree. The names are in the default position.
I need the names remain in the radial position (each name in front of your branch, the radial position).
Script used:
ggtree(tree,layout="circular",branch.length="none",aes(color=group))+ geom_text(aes(label=label, angle=angle), size=2,vjust=-0.3, hjust=1) +scale_color_manual(values=c("slateblue4","firebrick"))
Thanks.
Hi,
Thanks for the nice package.
I think the package installed correctly, but when I require it appears the following message:
Error in namespaceExport(ns, exports) : undefined exports: score, score<-
Could you help me?
Leifor
Reading trees with read.nhx
has some problems with short branch lengths when they are supplied in scientific notation, e.g.:
library(ggtree)
# two identical trees but with the branch length of node A written in scientific notation in the first case
short <- "((A:0.1e-3[&&NHX:Ev=S:S=1:ND=1],B:1[&&NHX:Ev=S:S=1:ND=2]):1[&&NHX:Ev=S:S=1:ND=3],C:1[&&NHX:Ev=S:S=1:ND=4]):1[&&NHX:Ev=S:S=1:ND=5];"
long <- "((A:0.001[&&NHX:Ev=S:S=1:ND=1],B:1[&&NHX:Ev=S:S=1:ND=2]):1[&&NHX:Ev=S:S=1:ND=3],C:1[&&NHX:Ev=S:S=1:ND=4]):1[&&NHX:Ev=S:S=1:ND=5];"
write(short, file = "~/short.tre")
write(long, file = "~/long.tre")
# both are parsed fine by read.tree
plot(read.tree("~/short.tre"))
plot(read.tree("~/long.tre"))
read.nhx("~/long.tre") # works
read.nhx("~/short.tre") # parsing never ends!
Hello,
I am trying to read and annotate a raxl tree with bootstrap in ggtree and i get the following error:
raxml_file <- system.file("extdata/RAxML", "/Desktop/standard-RAxML-master/RAxML_bipartitionsBrachLabels_18K_H3.tree", package="ggtree")
raxml <- read.raxml(raxml_file)
Error: could not find function "read.raxml"
Please let me know if there is a solution to this problem.
Thanks
When viewing trees with ggtree (but not with default tree viewing functionality), my tip labels appear to run off the image. Resizing the image once it is generated doesn't fix this. Is there any way to extend the area on which the tree is plotted such that the labels will fit?
Hi, thanks so much for this package! It's a million times easier than customizing every tree.
I have a weird issue where ggtree is not plotting a single terminal branch - here's the steps to reproduce:
library(ape)
library(ggtree)
tr<-read.tree(text="(C. sp. 1:0.356,(C. plicata:0.3,((C. guadeloupensis:0.223,((C. portoensis:0.158,C. virilis:0.201):0.005,((C. sp. 8:0.169,(C. angaria:0.031,C. castelli:0.037):0.131):0.073,(C. drosophilae:0.027,C. sp. 2:0.03):0.161):0.047):0.033):0.074,((C. kamaaina:0.14,(C. japonica:0.16,((C. imperialis:0.082,C. afra:0.182):0.009,((C. yunquensis:0.086,C. nouraguensis:0.085):0.038,C. macrosperma:0.159):0.057):0.012):0.059):0.041,(C. elegans:0.166,(((C. brenneri:0.129,C. doughertyi:0.111):0.042,(C. wallacei:0.083,C. tropicalis:0.07):0.033):0.013,(C. remanei:0.129,(C. sp. 5:0.127,(C. briggsae:0.047,C. nigoni:0.032):0.088):0.02):0.017):0.046):0.02):0.195):0.07):0.259);")
plot(tr)
ggtree(tr)+geom_text(aes(label=label),hjust=-0.05,fontface="italic")+geom_text(aes(label=branch.length, x=branch), size = 3,
vjust=-0.5, color="#F06C45") +
scale_x_continuous(breaks=seq(0, 60, 5))
C. imperalis - in the middle is not having its correct length plotted out - the branch length calculator seems to see it fine, but no length is plotted. I've tried deleting and adding branches, and there always seems to be one that is not plotted.
tmpTree <- read.tree(text="(t1:0.8578054991,(t5:0.2007951501,(t3:0.2035957272,(t2:0.5625704257,t4:0.1694741752):0.1775545834):0.160806458):0.3601662391);")
ggtree(tmpTree) + geom_hilight(9);
ggtree(tmpTree,layout="circular") + geom_hilight(9);
The geom_hilight works in the rectangular layout, but not the circular layout (no high lighting appears).
Apparently, not every tree have this problem. As in the following example, both layout works
tmpTree <- read.tree(text="(((t2:0.2664971272,t5:0.9326916183):0.5409086382,t1:0.7683936448):0.6352307415,(t3:0.5023543329,t4:0.06688197237):0.6074321754);")
ggtree(tmpTree) + geom_hilight(9)
ggtree(reorder(tmpTree),layout="circular") + geom_hilight(9)
I'm using ggtree_1.2.10
Hi! Thanks for the nice package. I was wondering if there is a way to label clades even if some tips have been collapsed? I tried:
require(ape)
set.seed(123)
tr <- rtree(10)
gtr <- ggtree(tr)
anno_gtr <- gtr+ geom_text(aes(label=node)) +geom_tiplab()
collapsed_anno_gtr <- anno_gtr%>% collapse(node=18)
collapsed_anno_gtr+ geom_cladelabel(node=17, "A")
Which gives me the following warnings and does not annotate clade:
Warning messages:
1: Removed 4 rows containing non-finite values (stat_clad_bar).
2: Removed 4 rows containing non-finite values (stat_clade_text).
3: Removed 4 rows containing missing values (geom_segment).
4: Removed 4 rows containing missing values (geom_segment).
5: Removed 4 rows containing missing values (geom_text).
6: Removed 1 rows containing missing values (geom_segment).
7: Removed 1 rows containing missing values (geom_text).
Thanks!
Hello,
Thank you for your ggtree package. I have a Bayesian tree with posterior probabilities used for node labels, with the outgroups collapsed to the root.
p <- ggtree(mbtree, layout = "circular", ndigits = 2) %>% collapse(node = 629) +
geom_tiplab(aes(label = label, angle=angle), size = 1, color = "steelblue", hjust = -0.1) +
geom_text(aes(x = branch, label = prob, angle = angle), size = 1, color = "black", vjust = -1.6)
My problem is that this code labels every terminal node with 1. When annotating/labelling, is there a way to differentiate between inner nodes and terminal nodes, or to hide all terminal node annotation?
Attached is an image of what I'm dealing with.
Best,
Nic
hosting images for posting in forum.
After midpoint rooting a tree, ggtree fails, with the getRoot function (called from inside ggtree()) reporting 'multiple roots founded'.
When called on the same tree from outside ggtree, getRoot only returns one root passed the same tree given to ggtree:
require(ape)
require(phangorn)
require(ggtree)
x<-rtree(10) # a random tree; this is handled correctly
getRoot(x) # correctly returns the root
ggtree(x) # succeeds
y<-midpoint(x) # midpoint root x, generating a new tree y using the phangorn midpoint rooting function
getRoot(y) # succeeds, returning one root
ggtree(y) # fails, reporting 'error in getRoot(tr) multiple roots founded (I think this should read 'found')
Is this a bug?
Thank you
David
Hi Guangchuang,
I installed the ggtree package via biocLite("ggtree") on Ubuntu 14.04 with R 3.2.3. When I use your example in the vignette for ggtree():
require(ape)
tr <- rtree(10)
ggtree(tr)
I get an error saying:
"Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
Error in ggtree(tr) : argument "form" is missing, with no default"
I have no clue why this occurs, especially since "form" is not an argument in the ggtree() function.
Thanks for your efforts so far, any help would be greatly appreciated.
Cheers,
Chris
Could you add support for reading NHX formatted files? It is an extended version of the standard newick format where comments with node or branch properties are allowed, eg:
((A[&&NHX:index=1]:1,B[&&NHX:S=2:index=2]:1):1,C[&&NHX:property=35:index=2]:1);
The comment string is included within a [&&NHX:
and a ]
and has a 'tag=value' format separated by semicolon in the case of multiple tags.
Nice package! I've been looking for something like this for a while. Noticed a bug in gplot.heatmap
where the levels of the heatmap aren't reordered properly and the labels don't match up with their respective values in the heatmap.
This line in gplot.heatmap
simply reorders the label:
levels(dd$Var1) <- df$label[order(df$y)]
This correctly reorders the levels:
dd$Var1 <- factor(dd$Var1, levels = df$label[order(df$y)])
Also, for very large heatmaps the tree and heatmap don't line up properly. It would be nice to see if this could be fixed because now it requires manually playing with the plot margins until it looks good.
Example:
t = rtree(1000)
data = as.data.frame(replicate(4, rnorm(1000)))
row.names(data) = t$tip.label
gplot(ggtree(t),data)
Here is some example code:
tree <- read.tree(system.file("extdata", "sample.nwk", package="ggtree"))
cp <- ggtree(tree) + geom_tiplab()
cp
cp <- cp %>% collapse(node=21)
cp
It leads to the following errors:
Error in unit(x, default.units) : 'x' and 'units' must have length > 0
In addition: Warning messages:
1: Removed 4 rows containing missing values (geom_segment).
2: Removed 4 rows containing missing values (geom_segment).
3: Removed 14 rows containing missing values (geom_text).
And, no tree is printed. I think that by default the behaviour should be to print out the remaining labels, attached to uncollapsed tips.
I am using ggtree version 1.0.20.
Thank you.
Anders.
Annotate_image() works well for adding custom icons to tree tips, but I would like to be able to create a ggplot legend for icons that I map to tree tips based on some column in the tree$data data frame. For example, if I create a tree of bacterial isolates, I might map isolate subtype to the tip label color and the source of the isolate to a set of custom icons. I have examined the source code for annotate_image() and geom_tiplab(), but I do not know enough about custom geoms and rasterGrob manipulation to see how to create this hybrid myself.
You might also consider changing annotate_image() so that the offset parameter has an effect when align = FALSE. Setting xmin <- x - width/2 + offset
made my trial tree plots look much nicer than having the center of the icon at the end of the branch.
Your work on this package is much appreciated - it's completely changed for the better how I plot trees in R.
I upgraded my installation of ggtree today from the bioconductor version to the current github version because I had a special request for the ggtree(ladderize = TRUE) feature, but the upgrade had the unexpected side effect of removing the hjust parameter for annotation_clade2() function.
Eg. I get the error message "Error: Unknown parameters: hjust" under the github version but not the bioconductor version for the following.
ttree <- read.tree(file = "example.tree.txt")
ttree <- midpoint(ttree)
gtree <- ggtree(ttree, ladderize = FALSE)
mytree <- gtree + geom_text(aes(label =label), hjust = -0.03)
annotation_clade2(mytree, tip1 = "C", tip2 = "D", label = "test", angle = 0, hjust = 0)
I still see the error if ladderize = TRUE on the github version.
Hi Guangchuang Yu,
First of all thank you for your ggtree package, it is truly versatile and really takes advantage of the good stuff from ggplot2!
I am currently preparing a figure for publication about trait variation and evolution across fiddler crab species. My goal is to have a figure that looks like this: http://ape-package.ird.fr/image/Figure2_TEJEDO.png (Richter-Boix A., Tejedo M. & Rezende E. L. 2011).
Attempt: (attached)
I created a dendogram using ggtree and a ggplot of trait (size) vs species (order). The species name is at the tip of the dendogram. I used ggExtra to arrange them in such a way. While it looks ok, the alignment is not proper.
Request:
Is there a way to align a ggplot like this one with each taxa from ggtree? This will be similar to what has been done with the gheatmap, if we can somehow make the dendogram the x-axis of the ggplot, that would be awesome!
Thank you so much in advance!
Putter
Very useful function in concept, but I couldn't get it to work. Looking at the source code, I have to wonder if it's not because it's basically a wrapper around ape's extract.clade(), which accepts a phylo object, while get.offspring.tip() accepts a ggtree object.
For now I'll probably run get.offspring.df() and filter out the internal nodes.
hi there,
thanks for your amazing package!
I think that if you turn this line (and possibly for other aes) in geom_tree
:
color <- c(color, color)
into color <- rep(color, 2)
we could directly pass factors to geom_tree (as their column names on the data.frame (or the data.frame resulting from the as.data.frame on the phylo objects). c
function converts factors into numeric while rep
retains the class.
all the best,
v
Hi
I am trying to use gheatmap and create a heatmap with just one variable. Its crashing. can you please let me know if it works for you.
Also i am using this code and the error. Can you please tell me what the error means so that i can fix the inputs
genotype1 <- read.table("hh_heatmap.txt", sep="\t", stringsAsFactor=F, header = TRUE)
gheatmap(p, genotype1)
Error in if (any(dd$value == "")) { :
missing value where TRUE/FALSE needed
Hi, thanks for the excellent phylogenetic tree annotator.
I am trying to read in BEAST MCC tree files (I have tested several) as newick files, however I first get the error:
Error in read.tree(nwk) :
The tree has apparently singleton node(s): cannot read tree file.
Reading Newick file aborted at tree no. 1
Then applying ggtree:::rm.singleton.newick(nwk,outfile=NULL) results in another error:
Error in ggtree:::rm.singleton.newick(nwk, outfile = NULL) :
can't parse singleton node...
(Note that when I just call rm.singleton.newick, I get the error:
Error: could not find function "rm.singleton.newick")
Any help would be greatly appreciated. Happy to provide further information.
Pinky
Not sure if the following can be done currently with ggtree:
I want to annotate a tree with the tip sequences, but I want to see the letters of the sequences rather than just the colors. Right now I do
p <- ggtree(t) + geom_tiplab(size=tip_size) + geom_tippoint(size=3) + geom_treescale()
msaplot(p, "tmp.fasta")
where tmp.fasta is the fasta file. But these lines just show colors and I want the letters. I have short sequences of 30 letters, so visually this would be meaningful.
Hi!
It would be great if ggtree would allow you to rotate and open up a fan/circular tree layout like in ape
here is some rough code to plot some examples
library(ape)
library(geiger) # to access whales data
data("whales")
tr = whales$phy # select whales tree
old.par <- par(mfrow=c(1, 3)) # grid plots
plot(tr, show.tip.label = FALSE, type = "f")
title(main = "Orignal")
plot(tr, show.tip.label = FALSE, type = "f", open.angle = 20, rotate.tree = 10)
axisPhylo()
title(main = "Rotate & Open for axis")
plot(tr, show.tip.label = FALSE, type = "f", open.angle = 180)
title(main = "Open to 180 degrees")
par(old.par)
the first plot is the original, the second is where open.angle and rotate.tree are used so axis.phylo() can be used. the third plot is where open.angle is used to plot the tree as a semicircle.
Thank you for your help and for developing/maintaining/expanding this great package!
Hi,
I need to draw a tree with phenotypic data, have only quantitative data.
My file is an array.How do I convert my file to this format?
For example
It can make the R using the GGtree?
The arguments low
and high
are ignored in the gheatmap
function when the input is of the type character
. This arguments work for numeric
values. Is there a chance to set a color scale for characters?
set.seed(1440)
tr <- rtree(20)
df <- data.frame(AA = rnorm(20), BB = rnorm(20))
rownames(df) <- tr$tip.label
p <- ggtree(tr)
gheatmap(p, df, low = "white", high = "black")
df <- data.frame(AA = LETTERS[1:20], BB = letters[1:20])
rownames(df) <- tr$tip.label
## Scale fill is ignored
gheatmap(p, df, low = "white", high = "black")
Thanks for the answer.
R version 3.2.4 (2016-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] gridExtra_2.2.1 org.Hs.eg.db_3.2.3 GO.db_3.2.2 clusterProfiler_2.4.3 RSQLite_1.0.0 DBI_0.3.1
[7] mygene_1.6.0 GenomicFeatures_1.22.13 AnnotationDbi_1.32.3 Biobase_2.30.0 GenomicRanges_1.22.4 GenomeInfoDb_1.6.3
[13] IRanges_2.4.8 S4Vectors_0.8.11 BiocGenerics_0.16.1 BiocInstaller_1.20.1 Rcpp_0.12.3 ggtree_1.2.17
[19] ggplot2_2.1.0 ape_3.4
loaded via a namespace (and not attached):
[1] lattice_0.20-33 tidyr_0.4.1 png_0.1-7 Rsamtools_1.22.0 Biostrings_2.38.4
[6] digest_0.6.9 assertthat_0.1 R6_2.1.2 plyr_1.8.3 chron_2.3-47
[11] futile.options_1.0.0 acepack_1.3-3.3 httr_1.1.0 sqldf_0.4-10 zlibbioc_1.16.0
[16] lazyeval_0.1.10 curl_0.9.6 SparseM_1.7 rpart_4.1-10 qvalue_2.2.2
[21] gsubfn_0.6-6 proto_0.3-10 labeling_0.3 splines_3.2.4 BiocParallel_1.4.3
[26] stringr_1.0.0 foreign_0.8-66 topGO_2.22.0 igraph_1.0.1 RCurl_1.95-4.8
[31] biomaRt_2.26.1 munsell_0.4.3 rtracklayer_1.30.3 KEGGREST_1.10.1 nnet_7.3-12
[36] SummarizedExperiment_1.0.2 Hmisc_3.17-2 XML_3.98-1.4 dplyr_0.4.3 GenomicAlignments_1.6.3
[41] bitops_1.0-6 grid_3.2.4 nlme_3.1-125 jsonlite_0.9.19 gtable_0.2.0
[46] magrittr_1.5 scales_0.4.0 graph_1.48.0 stringi_1.0-1 GOSemSim_1.28.2
[51] XVector_0.10.0 reshape2_1.4.1 latticeExtra_0.6-28 DO.db_2.9 futile.logger_1.4.1
[56] Formula_1.2-1 lambda.r_1.1.7 RColorBrewer_1.1-2 tools_3.2.4 survival_2.38-3
[61] colorspace_1.2-6 cluster_2.0.3 DOSE_2.8.2
I really like what you have done here!
Not sure if this is a bug or a feature request, but the flip and rotate functions don't seem to work well when layout ='unrooted'. I get overlapping lines. From a quick guess, it looks like the parents are set up differently for these layouts?
Please let me know if you would like any more details, such as an example nwk file and code.
Thanks,
ryan
It would be great to have a geom_ring to go with circular trees where at least at first binary data could be plotted (a point if data 1, and blank if 0 or empty). I assume it would use much the similar code used to calculate were to plot tip labels (perhaps something like this: https://medicine.tcd.ie/clinical_microbiology/research/murphy.php).
Ideally, we would be able to add multiple geom_rings to a single ggtree, each offset by a bit.
Or, even more ambitious would be to have a circular ggheatmap function.
Thank you.
Anders.
ggtree
is a cool package.
I want to expand the phylogenetic tree.
I'm glad and if there is a function, such as the zoom
function of the ape
package
Installation via bioconductor is working fine. source('https://bioconductor.org/biocLite.R');biocLite('ggtree')
but not in developer's version.
> devtools::install_github('GuangchuangYu/ggtree')
Downloading GitHub repo GuangchuangYu/ggtree@master
Installing ggtree
'/usr/lib64/R/bin/R' --no-site-file --no-environ --no-save --no-restore CMD \
INSTALL '/tmp/RtmpQM5w6s/devtools3de51ea1f4a0/GuangchuangYu-ggtree-ea9d661' \
--library='/usr/lib64/R/library' --install-tests
* installing *source* package ‘ggtree’ ...
** R
** inst
** tests
** preparing package for lazy loading
Creating a generic function for ‘nchar’ from package ‘base’ in package ‘S4Vectors’
- Error : object ‘GeomPoint’ is not exported by 'namespace:ggplot2'
- ERROR: lazy loading failed for package ‘ggtree’
- * removing ‘/usr/lib64/R/library/ggtree’
- Error: Command failed (1)
- Execution halted
The install in R 3.1.0 fails because of a namespace error.
*installing source package ‘ggtree’ ...
*_R
*_inst
*_tests
*_preparing package for lazy loading
Error : object ‘%<>%’ is not exported by 'namespace:magrittr'
ERROR: lazy loading failed for package ‘ggtree’
The installation process fails for both installing directly from github or using a tar-ball. Are there any dependencies that can cause this?
Hi,
any advise why I cannot install ggtree
?
devtools::install_github("GuangchuangYu/ggtree")
Downloading github repo GuangchuangYu/ggtree@master
Installing ggtree
Skipping 1 packages not available: Biostrings
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore CMD INSTALL \
'/tmp/Rtmp7plp5Y/devtools9ab788b5182/GuangchuangYu-ggtree-b82ce5a' \
--library='/home/paterno/R/x86_64-pc-linux-gnu-library/3.2' --install-tests
* installing *source* package ‘ggtree’ ...
** R
** inst
** tests
** preparing package for lazy loading
Creating a generic function for ‘nchar’ from package ‘base’ in package ‘S4Vectors’
Error : objeto ‘GeomPoint’ não foi exportado por 'namespace:ggplot2'
ERROR: lazy loading failed for package ‘ggtree’
* removing ‘/home/paterno/R/x86_64-pc-linux-gnu-library/3.2/ggtree’
Erro: Command failed (1)
Hi,
Thanks for the nice package. Just successfully installed ggtree via github on R 3.1.2 (devtools::install_github("GuangchuangYu/ggtree")
), but was unable to install via Bioconductor:
source("http://bioconductor.org/biocLite.R")
biocLite("ggtree")
Even though the depends on is R >=3.1.0 I get an error message :
Warning message:
package ‘ggtree’ is not available (for R version 3.1.2)
In case it is helpful I am running Linux Fedora 19 (and yes probably time to update R. :)) and session info when trying to install via Bioconductor is:
R version 3.1.2 (2014-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BiocInstaller_1.16.5
loaded via a namespace (and not attached):
[1] tools_3.1.2
Hi,
Thanks for the great package! I have two questions:
geom_label
, which has been added to the dev version of ggplot2
? This would be nice for mapping something e.g. an expression value to the background of the tip label (using the fill
aesthetic in geom_label()
).iris
+ ape::bionj()
example in the vignette, I get lots of warnings from ggplot2
when I try to add geom_label(aes(label = label))
, e.g. Warning message: Removed 148 rows containing missing values (geom_text).
However I think all the tip labels are being printed successfully. Do you know what causes this warning?Thanks again
Tom
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8 LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ape_3.3 ggplot2_1.0.1.9002 ggtree_1.1.21
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 lattice_0.20-33 IRanges_2.2.7 Biostrings_2.36.4 digest_0.6.8
[6] plyr_1.8.3 grid_3.2.2 jsonlite_0.9.17 nlme_3.1-122 gtable_0.1.2
[11] magrittr_1.5 stats4_3.2.2 scales_0.3.0 stringi_0.5-5 zlibbioc_1.14.0
[16] reshape2_1.4.1 XVector_0.8.0 rstudioapi_0.3.1 S4Vectors_0.6.5 labeling_0.3
[21] tools_3.2.2 stringr_1.0.0 munsell_0.4.2 parallel_3.2.2 BiocGenerics_0.14.0
[26] colorspace_1.2-6 gridExtra_2.0.0
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.