View source: R/geom_junction_label_repel.R
geom_junction_label_repel | R Documentation |
geom_junction_label_repel()
labels junction curves at their midpoint using
ggrepel::geom_label_repel()
. This can be useful to label and compare
junctions (plotted using geom_junction()
) with metrics of their usage (e.g.
read counts or percent-spliced-in).
geom_junction_label_repel(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
parse = FALSE,
...,
junction.orientation = "alternating",
junction.y.max = 1,
angle = 90,
ncp = 15,
box.padding = 0.25,
label.padding = 0.25,
point.padding = 1e-06,
label.r = 0.15,
label.size = 0.25,
min.segment.length = 0,
arrow = NULL,
force = 1,
force_pull = 1,
max.time = 0.5,
max.iter = 10000,
max.overlaps = getOption("ggrepel.max.overlaps", default = 10),
nudge_x = 0,
nudge_y = 0,
xlim = c(NA, NA),
ylim = c(NA, NA),
na.rm = FALSE,
show.legend = NA,
direction = c("both", "y", "x"),
seed = NA,
verbose = FALSE,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
A data frame. If specified, overrides the default data frame defined at the top level of the plot. |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
parse |
If TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath |
... |
other arguments passed on to
|
junction.orientation |
|
junction.y.max |
|
angle |
A numeric value between 0 and 180, giving an amount to skew the control points of the curve. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point. |
ncp |
The number of control points used to draw the curve. More control points creates a smoother curve. |
box.padding |
Amount of padding around bounding box, as unit or number.
Defaults to 0.25. (Default unit is lines, but other units can be specified
by passing |
label.padding |
Amount of padding around label, as unit or number.
Defaults to 0.25. (Default unit is lines, but other units can be specified
by passing |
point.padding |
Amount of padding around labeled point, as unit or
number. Defaults to 0. (Default unit is lines, but other units can be
specified by passing |
label.r |
Radius of rounded corners, as unit or number. Defaults
to 0.15. (Default unit is lines, but other units can be specified by
passing |
label.size |
Size of label border, in mm. |
min.segment.length |
Skip drawing segments shorter than this, as unit or
number. Defaults to 0.5. (Default unit is lines, but other units can be
specified by passing |
arrow |
specification for arrow heads, as created by |
force |
Force of repulsion between overlapping text labels. Defaults to 1. |
force_pull |
Force of attraction between a text label and its corresponding data point. Defaults to 1. |
max.time |
Maximum number of seconds to try to resolve overlaps. Defaults to 0.5. |
max.iter |
Maximum number of iterations to try to resolve overlaps. Defaults to 10000. |
max.overlaps |
Exclude text labels when they overlap too many other things. For each text label, we count how many other text labels or other data points it overlaps, and exclude the text label if it has too many overlaps. Defaults to 10. |
nudge_x , nudge_y |
Horizontal and vertical adjustments to nudge the
starting position of each text label. The units for |
xlim , ylim |
Limits for the x and y axes. Text labels will be constrained to these limits. By default, text labels are constrained to the entire plot area. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
direction |
"both", "x", or "y" – direction in which to adjust position of labels |
seed |
Random seed passed to |
verbose |
If |
inherit.aes |
If |
geom_junction_label_repel()
requires the following aes()
; xstart
,
xend
, y
(e.g. transcript name) and label
. Under the hood,
geom_junction_label_repel()
generates the same junction curves as
geom_junction()
to obtain curve midpoints for labeling. Therefore, it is
important that users use the same input data and parameters that alter
junction curves (namely junction.orientation
, junction.y.max
, angle
,
ncp
) for geom_junction_label_repel()
that they have used for
geom_junction()
.
the return value of a geom_*
function is not intended to be
directly handled by users. Therefore, geom_*
functions should never be
executed in isolation, rather used in combination with a
ggplot2::ggplot()
call.
library(magrittr)
library(ggplot2)
# to illustrate the package's functionality
# ggtranscript includes example transcript annotation
sod1_annotation %>% head()
# as well as a set of example (unannotated) junctions
# originating from GTEx and downloaded via the Bioconductor package snapcount
sod1_junctions
# extract exons
sod1_exons <- sod1_annotation %>% dplyr::filter(
type == "exon",
transcript_name == "SOD1-201"
)
sod1_exons %>% head()
# add transcript_name to junctions for plotting
sod1_junctions <- sod1_junctions %>%
dplyr::mutate(transcript_name = "SOD1-201")
# geom_junction_label_repel() can be used to label junctions
base <- sod1_exons %>%
ggplot(aes(
xstart = start,
xend = end,
y = transcript_name
)) +
geom_range() +
geom_intron(
data = to_intron(sod1_exons, "transcript_name")
)
# this can be useful to label junctions with their counts
base +
geom_junction(
data = sod1_junctions,
junction.y.max = 0.5
) +
geom_junction_label_repel(
data = sod1_junctions,
aes(label = round(mean_count, 2)),
junction.y.max = 0.5
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.