ggrepel functions | R Documentation |
These functions are minor modifications of those in the ggrepel package.
geom_dag_text_repel()
adds text directly to the plot.
geom_dag_label_repel()
draws a rectangle underneath the text, making it
easier to read. The text labels repel away from each other and away from the
data points. geom_dag_label_repel2()
is a slightly stylized version of
geom_dag_label_repel()' that often looks better on DAGs.
geom_dag_text_repel(
mapping = NULL,
data = NULL,
parse = FALSE,
...,
box.padding = 1.25,
point.padding = 1.5,
segment.color = "#666666",
fontface = "bold",
segment.size = 0.5,
arrow = NULL,
force = 1,
max.iter = 2000,
nudge_x = 0,
nudge_y = 0,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_dag_label_repel(
mapping = NULL,
data = NULL,
parse = FALSE,
...,
box.padding = grid::unit(1.25, "lines"),
label.padding = grid::unit(0.25, "lines"),
point.padding = grid::unit(1.5, "lines"),
label.r = grid::unit(0.15, "lines"),
label.size = 0.25,
segment.color = "grey50",
segment.size = 0.5,
arrow = NULL,
force = 1,
max.iter = 2000,
nudge_x = 0,
nudge_y = 0,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_dag_label_repel2(
mapping = NULL,
data = NULL,
box.padding = 2,
max.overlaps = Inf,
label.size = NA,
...
)
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. |
parse |
If TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath |
... |
other arguments passed on to
|
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 |
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 |
segment.color , segment.size |
See |
fontface |
A character vector. Default is "bold" |
arrow |
specification for arrow heads, as created by |
force |
Force of repulsion between overlapping text labels. Defaults to 1. |
max.iter |
Maximum number of iterations to try to resolve overlaps. Defaults to 10000. |
nudge_x , nudge_y |
Horizontal and vertical adjustments to nudge the
starting position of each text label. The units for |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
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 |
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. |
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. |
library(ggplot2)
g <- dagify(
m ~ x + y,
y ~ x,
exposure = "x",
outcome = "y",
latent = "m",
labels = c("x" = "Exposure", "y" = "Outcome", "m" = "Collider")
)
g %>%
tidy_dagitty() %>%
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point() +
geom_dag_text_repel(aes(label = name), show.legend = FALSE) +
theme_dag()
g %>%
tidy_dagitty() %>%
dag_label(labels = c(
"x" = "This is the exposure",
"y" = "Here's the outcome",
"m" = "Here is where they collide"
)) %>%
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point() +
geom_dag_text() +
geom_dag_label_repel(
aes(label = label, fill = label),
col = "white",
show.legend = FALSE
) +
theme_dag()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.