Description Usage Arguments Details Value Author(s) Examples
'geom_fruit()' can automatically re-arrange the input 'data' according to the tree structure. It can present the associated data on the external panels of the tree using the 'geom' function defined in 'ggplot2' or other ggplot2-based packages with aesthetic 'mapping' and other parameters, and it will align the external layers in the outer ring of circular layout tree or with rectangular layout tree side by side. Note: the tree should be created by 'ggtree'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | geom_fruit(
mapping,
data = NULL,
geom,
offset = 0.03,
pwidth = 0.2,
position = "auto",
grid.params = NULL,
axis.params = list(axis = "none", text.angle = 0, text.size = 0.8, text = NULL, title
= NULL, title.size = 3, title.height = 0.1, title.angle = 0, title.color = "black",
nbreak = 4, line.size = 0.2, line.color = "grey", line.alpha = 1, ...),
...
)
fruit_plot(
p,
data = NULL,
geom,
mapping,
offset = 0.03,
pwidth = 0.2,
position = "auto",
...
)
|
mapping |
aes mapping for 'geom' |
data |
data to plot by 'geom', the column contained tree tip labels should be as y in mapping. |
geom |
geom function to plot the data. |
offset |
numeric, distance between external layers or between tree and external layers, default is 0.03, meaning the 0.03 times of x range of tree (0.03 * xrange of tree). |
pwidth |
numeric, the width of external geometric layer, default is 0.2, meaning the 0.2 times of x range of tree (0.2 * xrange of tree). |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function, default is 'auto', see details in the following. |
grid.params |
list, the parameters to control the attributes of grid lines, default is NULL, see the grid.params in the following. grid.params control the attributes of grid line of external layer, it can be referred to the following parameters: ##'
|
axis.params |
list, the parameters to control the attributes of pseudo axis, see the axis.params in the following. axis.params control the attributes of axis, it can be referred to the following parameters:
|
... |
additional parameters for 'geom' |
p |
tree view |
The 'data' parameter is data.frame or tibble type, it is the same with the data for corresponding geometric layers, but it must contain one column of taxa labels of tree, it will be mapped to 'y' axis in 'mapping'. When 'data' is not provided, the associated data in tree data will be extracted automatically, and the 'y' axis don't need to be mapped.
The 'mapping' parameter is setting of aesthetic mappings created by 'aes()' or 'aes_()' of 'ggplot2', the 'y' should be assigned to the variable names of column of taxa labels in data.frame of 'data', only if the 'data' is not provided, see the above.
The 'geom' parameter is the geometric function defined in 'ggplot2' or other 'ggplot2-extension', e.g.
ggplot2 | geom_bar,geom_col,geom_boxplot,geom_violin,geom_tile | circular, rectangular |
ggmsa | geom_msa | rectangular |
ggstar | geom_star | circular, rectangular |
ggimage | geom_image,geom_phylopic | circular, rectangular |
ggpmisc | geom_plot,geom_table | circular, rectangular |
ggridges | geom_density_ridges | circular, rectangular |
ggtext | geom_richtext | circular, rectangular |
... |
if the 'geom' is 'geom_bar', 'geom_col', 'geom_boxplot', 'geom_violin', the 'orientation' should be specified to 'y'.
The default 'position' parameter is 'auto', it will guess and determine (hopefully) a suitable position for the specified geometric layer. That means using 'position_stackx()' for geom_bar(), 'position_dodgex()' for 'geom_violin()' and 'geom_boxplot()', and 'position_identityx()' for others (e.g. geom_point() and geom_tile() etc.). A geometric layer that has a position parameter should be compatible with geom_fruit(), as it allows using position functions defined in the ggtreeExtra package to adjust output layer position.
and the grid line also can be added using 'grid.params=list(...)'.
The axis line and text can be added using 'axis.params=list(axis="x",...)'.
The 'p' parameter only work when you use fruit_plot()
, which is alias of geom_fruit()
.
ggplot object
Shuangbin Xu and Guangchuang Yu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | library(ggtree)
library(ggplot2)
library(ggstar)
set.seed(1024)
tr <- rtree(100)
dd = data.frame(id=tr$tip.label, value=abs(rnorm(100)))
dt = data.frame(id=tr$tip.label, group=c(rep("A",50),rep("B",50)))
p <- ggtree(tr, layout="circular")
p1 <- p +
geom_fruit(
data=dt,
geom=geom_star,
mapping=aes(y=id, fill=group),
size=2.5,
starstroke=0
)
p2 <- p1 +
geom_fruit(
data=dd,
geom=geom_bar,
mapping=aes(x=value, y=id),
orientation="y",
stat="identity"
)
p3 <- fruit_plot(
p=p,
data=dt,
geom=geom_star,
mapping=aes(y=id, fill=group),
size=2.5,
starstroke=0
)
p4 <- fruit_plot(
p=p3,
data=dd,
geom=geom_bar,
mapping=aes(x=value, y=id),
orientation="y",
stat="identity"
)
p <- p %<+% dd %<+% dt
p5 <- p +
geom_fruit(
geom = geom_star,
mapping = aes(y=id, fill=group),
size = 2.5,
starstroke = 0
) +
geom_fruit(
geom = geom_bar,
mapping = aes(x=value, y=id),
orientation = "y",
stat = 'identity'
)
|
Registered S3 method overwritten by 'treeio':
method from
root.phylo ape
ggtree v2.4.1 For help: https://yulab-smu.top/treedata-book/
If you use ggtree in published research, please cite the most appropriate paper(s):
[36m-[39m Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics, 2020, 69:e96. doi:10.1002/cpbi.96
[36m-[39m Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
[36m-[39m Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.