View source: R/safe_edge_label_positions.R
safe_edge_label_position | R Documentation |
Move the edge labels away from path intersections.
safe_edge_label_position(
object,
layout = NULL,
default_pos = 0.5,
tolerance = 0.05,
update_plot = TRUE
)
object |
It can be the output of
|
layout |
A layout matrix.
Required if |
default_pos |
Used if |
tolerance |
If the distance between a position and an intersection is greater than this distance, then a position is considered safe and will not be adjusted. |
update_plot |
Logical. Used on
if |
This function identify all intersection points between two paths in a model, and set the position of an edge label to the mid-point of a line segment between an intersection point and the another intersection point or the origin/destination of a path.
This function is intended for having
a "likely" readable graph with as
little user-intervention as possible.
If precise control of the edge label
positions is desired, use
set_edge_label_position()
.
If object
is a lavaan
-class
object, it returns
a named numeric vector of edge
positions to be used by
set_edge_label_position()
.
If object
is a qgraph
object
and update_plot
is TRUE
, it
returns a qgraph
object with the
adjusted edge label positions.
Otherwise, it returns a named vector
of the position to be adjusted, as
for a lavaan
-class object.
set_edge_label_position()
on setting the positions of edge
labels.
library(lavaan)
library(semPlot)
# Create a dummy dataset
mod_pa <-
"
m11 ~ c1 + x1
m12 ~ c2 + m11 + m21
m21 ~ c1 + x1
m22 ~ c1 + m21 + m11
y ~ m12 + m22 + x1
"
fit <- lavaan::sem(
mod_pa,
do.fit = FALSE
)
dat <- simulateData(
parameterTable(fit),
sample.nobs = 500,
seed = 1234
)
fit <- lavaan::sem(
mod_pa,
dat
)
# Set the layout
m <- auto_layout_mediation(
fit,
exclude = c("c1", "c2", "c3")
)
pos_new <- safe_edge_label_position(
fit,
layout = m
)
pos_new
pm <- semPlotModel(fit) |> drop_nodes(c("c1", "c2"))
p <- semPaths(
pm,
whatLabels = "est",
layout = m,
DoNotPlot = TRUE
)
# Three labels overlap with each other
plot(p)
# Update the plot
p_safe <- p |> safe_edge_label_position()
# Three labels do not overlap in this plot
plot(p_safe)
# Set the position manually
p_safe2 <- p |>
set_edge_label_position(pos_new)
plot(p_safe2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.