Title: | Draw Gene Arrow Maps in 'ggplot2' |
---|---|
Description: | A 'ggplot2' extension for drawing gene arrow maps. |
Authors: | David Wilkins [aut, cre], Zachary Kurtz [ctb] |
Maintainer: | David Wilkins <[email protected]> |
License: | GPL-2 |
Version: | 0.5.1.9002 |
Built: | 2025-02-20 05:15:54 UTC |
Source: | https://github.com/wilkox/gggenes |
Dummy genes, similar to those generated with make_alignment_dummies()
, for
example purposes only.
example_dummies
example_dummies
A data frame with eight rows and three variables:
the genome
the start position of the dummy
the end position of the dummy
the name of the dummy gene
Genetic features for example purposes only.
example_features example_features_polar
example_features example_features_polar
A data frame with 23 rows and five variables:
the genome
the name of the feature
the type of the feature
the position of the feature
is the feature oriented, and if so in the forward direction?
An object of class data.frame
with 6 rows and 5 columns.
Genes for example purposes only.
example_genes example_genes_polar example_subgenes example_subgenes_polar
example_genes example_genes_polar example_subgenes example_subgenes_polar
A data frame with 72 rows and six variables:
the genome
the name of the gene
the start position of the gene
the end position of the gene
the strand of the gene
the orientation of the gene
example_subgenes (143 rows) also contains:
the name of the subgene
the start position of the subgene segment
the end position of the subgene segment
An object of class data.frame
with 18 rows and 6 columns.
An object of class data.frame
with 143 rows and 9 columns.
An object of class data.frame
with 40 rows and 9 columns.
Terminators for example purposes only.
example_terminators example_terminators_polar
example_terminators example_terminators_polar
A data frame with two rows and three variables:
the genome
the name of the terminator
the position of the terminator
An object of class data.frame
with 2 rows and 3 columns.
geom_feature()
draws lines to indicate the positions of point genetic
features, for example restriction sites, origins of replication or
transcription start sites.
geom_feature( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = FALSE, feature_height = unit(3, "mm"), feature_width = unit(3, "mm"), arrowhead_width = unit(2, "mm"), ... )
geom_feature( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = FALSE, feature_height = unit(3, "mm"), feature_width = unit(3, "mm"), arrowhead_width = unit(2, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for ggplot2. inherit.aes is set to FALSE by default, as features are not likely to share any plot aesthetics other than y. |
feature_height |
|
feature_width |
|
arrowhead_width |
|
Features are drawn as vertical lines extending from the horizontal line
representing the molecule. The position of the feature is expressed with the
x
aesthetic. Optionally, the forward
aesthetic can be used to specific
an orientation for the feature (e.g. the direction of transcription), in
which case an angled arrowhead will be added. The forward
aesthetic
assumes that the x-axis is oriented in the normal direction, i.e. increasing
from left to right; if it is not, the values in forward
will need to be
inverted manually.
x (required; position of the feature)
y (required; molecule)
forward (optional; if TRUE, or a value coercible to TRUE, the feature will be drawn with an arrowhead pointing right, if FALSE, pointing left, if NA, the feature will be drawn as a vertical line)
alpha
colour
linetype
linewidth (the former size aesthetic has been deprecated and will be removed in future versions)
geom_feature_label()
, geom_terminator()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_feature(data = example_features, ggplot2::aes(x = position, y = molecule, forward = forward)) + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_feature(data = example_features, ggplot2::aes(x = position, y = molecule, forward = forward)) + ggplot2::facet_wrap(~ molecule, scales = "free")
geom_feature_label()
adds text labels to features drawn with
geom_feature
().
geom_feature_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = FALSE, feature_height = unit(4, "mm"), label_height = unit(3, "mm"), ... )
geom_feature_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = FALSE, feature_height = unit(4, "mm"), label_height = unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for ggplot2. inherit.aes is set to FALSE by default, as features are not likely to share any plot aesthetics other than y. |
feature_height |
|
label_height |
|
Standard 'ggplot2' aesthetics for text are supported (see Aesthetics).
x (required; position of the feature)
y (required; molecule)
label (required; the label text)
forward (optional; will draw text in the appropriate location for features with angled arrowheads)
colour
size
alpha
family
fontface
angle
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_feature(data = example_features, ggplot2::aes(x = position, y = molecule, forward = forward)) + geom_feature_label(data = example_features, ggplot2::aes(x = position, y = molecule, label = name, forward = forward)) + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_feature(data = example_features, ggplot2::aes(x = position, y = molecule, forward = forward)) + geom_feature_label(data = example_features, ggplot2::aes(x = position, y = molecule, label = name, forward = forward)) + ggplot2::facet_wrap(~ molecule, scales = "free")
geom_gene_arrow()
draws genes as arrows, allowing gene maps to be drawn.
geom_gene_arrow( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, arrowhead_width = grid::unit(4, "mm"), arrowhead_height = grid::unit(4, "mm"), arrow_body_height = grid::unit(3, "mm"), ... )
geom_gene_arrow( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, arrowhead_width = grid::unit(4, "mm"), arrowhead_height = grid::unit(4, "mm"), arrow_body_height = grid::unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for ggplot2. |
arrowhead_width |
|
arrowhead_height |
|
arrow_body_height |
|
This geom draws genes as arrows along a horizontal line representing the
molecule. The start and end locations of the gene are expressed with the
xmin
and xmax
aesthetics, while the molecule can be specified with the
y
aesthetic. Optionally, an additional forward
aesthetic can be used to
reverse the orientation of some or all genes from that implied by xmin
and
xmax
.
Unless the plot is faceted with a free x scale, all the molecules will share
a common x axis. This means that if the locations are very different across
different molecules, the genes might appear very small and squished together
with a lot of unnecessary empty space. To get around this, either facet the
plot with scales = "free_x"
, or normalise the gene locations if their
exact locations are not important.
See make_alignment_dummies()
for a method to align genes between molecules.
xmin,xmax (start and end of the gene; will be used to determine gene orientation)
y (molecule)
forward (if any value that is not TRUE, or coercible to TRUE, the gene
arrow will be drawn in the opposite direction to that determined by xmin
and xmax
)
alpha
colour
fill
linetype
linewidth (the former size aesthetic has been deprecated and will be removed in future versions)
theme_genes()
, make_alignment_dummies()
, geom_gene_label()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::facet_wrap(~ molecule, scales = "free")
geom_gene_label()
can be used to add a text label to genes drawn with
geom_gene_arrow()
.
geom_gene_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(0.1, "lines"), align = "centre", min.size = 4, grow = F, reflow = F, height = grid::unit(3, "mm"), ... )
geom_gene_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(0.1, "lines"), align = "centre", min.size = 4, grow = F, reflow = F, height = grid::unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
Standard
geom arguments as for |
padding.x , padding.y
|
|
align |
Where inside the gene to place the text label. Default is 'centre'; other options are 'left' and 'right'. |
min.size |
Minimum font size, in points. If provided, text that would need to be shrunk below this size to fit inside the gene arrow will not be drawn. Defaults to 4 pt. |
grow |
If |
reflow |
If |
height |
|
geom_gene_label()
uses the 'ggfittext' package to fit text to genes. All
text drawing options available in ggfittext::geom_fit_text()
(growing,
reflowing, etc.) are also available here. For full details on how these
options work, see the documentation for ggfittext::geom_fit_text()
.
Standard 'ggplot2' aesthetics for text are supported (see Aesthetics).
xmin,xmax (start and end of the gene; required)
y (molecule; required)
label (the label text; required)
colour
size
alpha
family
fontface
angle
geom_gene_arrow
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) + geom_gene_arrow() + geom_gene_label() + ggplot2::facet_wrap(~ molecule, ncol = 1, scales = "free") + theme_genes()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) + geom_gene_arrow() + geom_gene_label() + ggplot2::facet_wrap(~ molecule, ncol = 1, scales = "free") + theme_genes()
geom_subgene_arrow()
draws subgenes segments within gene arrows drawn with
geom_gene_arrow()
.
geom_subgene_arrow( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, arrowhead_width = grid::unit(4, "mm"), arrowhead_height = grid::unit(4, "mm"), arrow_body_height = grid::unit(3, "mm"), ... )
geom_subgene_arrow( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, arrowhead_width = grid::unit(4, "mm"), arrowhead_height = grid::unit(4, "mm"), arrow_body_height = grid::unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for 'ggplot2'. |
arrowhead_width |
|
arrowhead_height |
|
arrow_body_height |
|
The start and end locations of the subgene are given with the xsubmin
and
xsubmax
aesthetics. geom_subgene_arrow()
requires some information about
the 'parent' gene, provided with the same aesthetics used for
geom_gene_arrow()
: start and end locations of the 'parent' gene with the
xmin
and xmax
aesthetics, the molecule with the y
aesthetic, and
optionally the direction with the forward
aesthetic. If the geometry of
the parent gene has been changed with arrowhead_width
, arrowhead_height
or arrow_body_height
, identical parameters should be given to
geom_subgene_arrow()
.
xmin,xmax (start and end of the gene; will be used to determine gene orientation)
xsubmin,xsubmax (start and end of subgene segment). Should be consistent
with xmin
/xmax
y (molecule)
forward (if FALSE, or coercible to FALSE, the gene arrow will be drawn in
the opposite direction to that determined by xmin
and xmax
)
alpha
colour
fill
linetype
linewidth (the former size aesthetic has been deprecated and will be removed in future versions)
geom_gene_arrow()
, geom_subgene_label()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule)) + geom_gene_arrow() + geom_subgene_arrow(data = example_subgenes, ggplot2::aes(xmin = start, xmax = end, xsubmin = from, xsubmax = to, y = molecule, fill = gene)) + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule)) + geom_gene_arrow() + geom_subgene_arrow(data = example_subgenes, ggplot2::aes(xmin = start, xmax = end, xsubmin = from, xsubmax = to, y = molecule, fill = gene)) + ggplot2::facet_wrap(~ molecule, scales = "free")
geom_subgene_label()
can be used to add a text label to subgenes drawn
with geom_subgene_arrow()
.
geom_subgene_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(0.1, "lines"), align = "centre", min.size = 4, grow = F, reflow = F, height = grid::unit(3, "mm"), ... )
geom_subgene_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, padding.x = grid::unit(1, "mm"), padding.y = grid::unit(0.1, "lines"), align = "centre", min.size = 4, grow = F, reflow = F, height = grid::unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
Standard
geom arguments as for |
padding.x , padding.y
|
|
align |
Where inside the subgene to place the text label. Default is 'centre'; other options are 'left' and 'right'. |
min.size |
Minimum font size, in points. If provided, text that would need to be shrunk below this size to fit inside the subgene will not be drawn. Defaults to 4 pt. |
grow |
If |
reflow |
If |
height |
|
geom_subgene_label()
uses the 'ggfittext' package to fit text to genes.
All text drawing options available in ggfittext::geom_fit_text()
(growing,
reflowing, etc.) are also available here. For full details on how these
options work, see the documentation for ggfittext::geom_fit_text()
.
Standard 'ggplot2' aesthetics for text are supported (see Aesthetics.)
xsubmin,xsubmax (start and end of the subgene; required)
y (molecule; required)
colour
size
alpha
family
fontface
angle
geom_terminator()
draws a 'T-shaped' glyph representing the position of a
transcription terminator.
geom_terminator( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = FALSE, terminator_height = unit(3, "mm"), terminator_width = unit(3, "mm"), ... )
geom_terminator( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = FALSE, terminator_height = unit(3, "mm"), terminator_width = unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for ggplot2. inherit.aes is set to FALSE by default, as terminators are not likely to share any plot aesthetics other than y. |
terminator_height |
|
terminator_width |
|
x (required; position of the terminator)
y (required; molecule)
alpha
color
linetype
linewidth (the former size aesthetic has been deprecated and will be removed in future versions)
geom_terminator_label()
, geom_feature()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_terminator(data = example_terminators, ggplot2::aes(x = position, y = molecule)) + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_terminator(data = example_terminators, ggplot2::aes(x = position, y = molecule)) + ggplot2::facet_wrap(~ molecule, scales = "free")
geom_terminator_label()
adds text labels to terminators drawn with
geom_terminator()
.
geom_terminator_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = FALSE, terminator_height = unit(4, "mm"), label_height = unit(3, "mm"), ... )
geom_terminator_label( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = FALSE, inherit.aes = FALSE, terminator_height = unit(4, "mm"), label_height = unit(3, "mm"), ... )
mapping , data , stat , position , na.rm , show.legend , inherit.aes , ...
|
As standard for ggplot2. inherit.aes is set to FALSE by default, as terminators are not likely to share any plot aesthetics other than y. |
terminator_height |
|
label_height |
|
Standard 'ggplot2' aesthetics for text are supported (see Aesthetics).
x (required; position of the terminator)
y (required; molecule)
label (required; the label text)
colour
size
alpha
family
fontface
angle
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_terminator(data = example_terminators, ggplot2::aes(x = position, y = molecule)) + geom_terminator_label(data = example_terminators, ggplot2::aes(x = position, y = molecule, label = name)) + ggplot2::facet_wrap(~ molecule, scales = "free")
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_terminator(data = example_terminators, ggplot2::aes(x = position, y = molecule)) + geom_terminator_label(data = example_terminators, ggplot2::aes(x = position, y = molecule, label = name)) + ggplot2::facet_wrap(~ molecule, scales = "free")
make_alignment_dummies()
helps you to visually align genes across
molecules that have been faceted with a free x scale. The output of this
function is a data frame of dummy genes. If these dummy genes are added to a
'ggplot2' plot with ggplot::geom_blank()
, they will extend the x axis
range in such a way that the start or end of a selected gene is visually
aligned across the facets.
make_alignment_dummies(data, mapping, on, side = "left")
make_alignment_dummies(data, mapping, on, side = "left")
data |
Data frame of genes. This is almost certainly the same data frame
that will later be passed to |
mapping |
Aesthetic mapping, created with |
on |
Name of gene to be visually aligned across facets. This gene must
be present in 'data', in the column mapped to the |
side |
Should the visual alignment be of the 'left' (default) or 'right' side of the gene? |
dummies <- make_alignment_dummies(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, id = gene), on = "genE") ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::geom_blank(data = dummies) + ggplot2::facet_wrap(~ molecule, scales = "free", ncol = 1)
dummies <- make_alignment_dummies(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, id = gene), on = "genE") ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::geom_blank(data = dummies) + ggplot2::facet_wrap(~ molecule, scales = "free", ncol = 1)
This theme removes extraneous plot elements for drawing an
'arrows-on-a-string' style gene map in 'ggplot2'.theme_genes_flipped()
is
like theme_genes()
, but for flipped coordinates.
theme_genes() theme_genes_flipped()
theme_genes() theme_genes_flipped()
This theme removes strip text (the text that labels facets when you use
ggplot2::facet_wrap()
or ggplot::facet_grid()
). This makes it easier to
draw molecules on different x scales by setting the y aesthetic to the
molecule, then faceting with facet_grid( ~ molecule, scales = "free")
.
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::facet_wrap(~ molecule, scales = "free") + theme_genes()
ggplot2::ggplot(example_genes, ggplot2::aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + ggplot2::facet_wrap(~ molecule, scales = "free") + theme_genes()