Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
# Temporarily disabled due to OpenMx's dependence on R 4.5.0
# - {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'release', nosuggests: true, special: "No Suggests"}

env:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: semptools
Title: Customizing Structural Equation Modelling Plots
Version: 0.3.2
Version: 0.3.2.1
Authors@R: c(
person(given = "Shu Fai",
family = "Cheung",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# semptools 0.3.2.1

## Improvement

- Updated to treat rectangles as
manifest variables and ellipses as
latent variables
(0.3.2.1)

# semptools 0.3.2

## New Features
Expand Down
12 changes: 6 additions & 6 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ node_plot <- function(semPaths_plot) {

man_plot <- function(semPaths_plot) {
nodes <- semPaths_plot$graphAttributes$Nodes
nodes$names[nodes$shape == "square"]
nodes$names[nodes$shape == "square"] | nodes$names[nodes$shape == "rectangle"]
}

#' @noRd

lat_plot <- function(semPaths_plot) {
nodes <- semPaths_plot$graphAttributes$Nodes
nodes$names[nodes$shape == "circle"]
nodes$names[nodes$shape == "circle"] | nodes$names[nodes$shape == "ellipse"]
}

#' @noRd

indicator_plot <- function(semPaths_plot) {
nodes <- semPaths_plot$graphAttributes$Nodes
man_id <- which(nodes$shape == "square")
lat_id <- which(nodes$shape == "circle")
man_id <- which((nodes$shape == "square") | (nodes$shape == "rectangle"))
lat_id <- which((nodes$shape == "circle") | (nodes$shape == "ellipse"))
edges <- as.data.frame(semPaths_plot$Edgelist)
edges2 <- edges[edges$directed & !edges$bidirectional, ]
id <- (edges2$from %in% lat_id) & (edges2$to %in% man_id)
Expand All @@ -39,8 +39,8 @@ loading_plot <- function(semPaths_plot,
# Assume that:
# squares are manifest variables
# circles are latent variables
man_id <- which(nodes$shape == "square")
lat_id <- which(nodes$shape == "circle")
man_id <- which((nodes$shape == "square") | (nodes$shape == "rectangle"))
lat_id <- which((nodes$shape == "circle") | (nodes$shape == "ellipse"))
edges <- as.data.frame(semPaths_plot$Edgelist)
edges2 <- edges[edges$directed & !edges$bidirectional, ]
id <- (edges2$from %in% lat_id) & (edges2$to %in% man_id)
Expand Down
21 changes: 13 additions & 8 deletions R/set_sem_layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ set_sem_layout <- function(semPaths_plot,
} else {
Nodes_names2 <- NA
}

if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "square"] %in% indicator_order)) {
if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "square"] %in% indicator_order)) {
tmp1 <- Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "square"]
tmp0 <- semPaths_plot$graphAttributes$Nodes$shape == "square" |
semPaths_plot$graphAttributes$Nodes$shape == "rectangle"
if (!all(Nodes_names[tmp0] %in% indicator_order)) {
if (!all(Nodes_names2[tmp0] %in% indicator_order)) {
tmp1 <- Nodes_names2[tmp0]
tmp2 <- indicator_order
msg_tmp <- setdiff(tmp1,
indicator_order)
Expand All @@ -299,8 +300,10 @@ set_sem_layout <- function(semPaths_plot,
indicator_order <- tmp
}
}
if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) {
if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) {
tmp0 <- (semPaths_plot$graphAttributes$Nodes$shape == "circle") |
(semPaths_plot$graphAttributes$Nodes$shape == "ellipse")
if (!all(Nodes_names[tmp0] %in% indicator_factor)) {
if (!all(Nodes_names2[tmp0] %in% indicator_factor)) {
warning("One or more factors in the graph are not in indicator_factor. Unexpected results may occur.")
} else {
tmp <- sapply(indicator_factor, function(x) {
Expand All @@ -320,10 +323,12 @@ set_sem_layout <- function(semPaths_plot,
# if (!all(Nodes_names[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in% indicator_factor)) {
# warning("One or more factors in the graph may not be in indicator_factor. Unexpected results may occur.")
# }
tmp0 <- (semPaths_plot$graphAttributes$Nodes$shape == "circle") |
(semPaths_plot$graphAttributes$Nodes$shape == "ellipse")
if (!all(indicator_factor %in% factor_layout[!is.na(factor_layout)])) {
if (!all(Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"] %in%
if (!all(Nodes_names2[tmp0] %in%
factor_layout[!is.na(factor_layout)])) {
tmp <- Nodes_names2[semPaths_plot$graphAttributes$Nodes$shape == "circle"]
tmp <- Nodes_names2[tmp0]
msg_tmp <- setdiff(tmp,
factor_layout[!is.na(factor_layout)])
msg_tmp <- paste(unlist(msg_tmp),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![R-CMD-check](https://github.com/sfcheung/semptools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sfcheung/semptools/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

(Version 0.3.2, updated on 2025-07-12, [release history](https://sfcheung.github.io/semptools/news/index.html))
(Version 0.3.2.1, updated on 2025-07-20, [release history](https://sfcheung.github.io/semptools/news/index.html))

# semptools <img src="man/figures/logo.png" align="right" height="150" />

Expand Down
Loading