geom_fruit | R Documentation |
'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'.
geom_fruit(
mapping,
data = NULL,
geom,
offset = 0.03,
pwidth = 0.2,
position = "auto",
inherit.aes = FALSE,
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, limits = NULL, ...),
...
)
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. |
inherit.aes |
logical, If 'FALSE', overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, default is FALSE. |
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
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_col,
mapping=aes(x=value, y=id)
)
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_col,
mapping = aes(x=value, y=id),
pwidth = .3,
axis.params = list(
axis = 'x',
text.size = 2,
nbreak = 2,
text.angle = -40,
vjust = 1,
hjust = 0,
limits = c(0, 2)
),
grid.params = list()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.