Create the layout matrix from a list of coordinates for semPaths.
Arguments
- ...
Each node in the matrix is specified by this form:
name = c(x, y). Thenameis the node label, and the vector is the position of the node. The first element is thexposition, and the second element is theyposition, measured from the top left corner. The size of the grid is determined automatically. For a grid of n rows and m columns, the top left cell is specified byc(1, 1), and the bottom right cell is specified byc(n, m).
Value
A layout matrix for the layout argument of
semPlot::semPaths().
Details
The layout argument in semPlot::semPaths() accepts a
matrix with node labels as the elements, and NA for empty cells.
This function allows user to create the matrix using a list of
coordinates for the node labels.
Note that semPlot::semPaths() only
treat a matrix as a layout matrix as
a matrix of grid if it has three or
more columns. Therefore, if the resulting
matrix has only one or two columns, it
will be converted to a matrix with
three columns, by inserting a column
of NAs for a two-column matrix, and
inserting the resulting matrix between
two columns of NAs for a one-column
matrix.
Examples
# Suppose this is the layout to be created:
m0 <- matrix(c("x1", NA, NA, NA,
"x2", "x3", NA, NA,
NA, "x4", NA, "x5"), byrow = TRUE, 3, 4)
# This call will create the same matrix.
m1 <- layout_matrix(x1 = c(1, 1),
x2 = c(2, 1),
x3 = c(2, 2),
x4 = c(3, 2),
x5 = c(3, 4))
#The two matrices should be identical.
m0 == m1
#> [,1] [,2] [,3] [,4]
#> [1,] TRUE NA NA NA
#> [2,] TRUE TRUE NA NA
#> [3,] NA TRUE NA TRUE
