Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.check_dag plots multiple adjustment sets #354

Merged
merged 2 commits into from
Aug 10, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: see
Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2'
Version: 0.8.5.4
Version: 0.8.5.5
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
17 changes: 17 additions & 0 deletions R/plot.check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ plot.see_check_dag <- function(x,
p1 <- p2 <- suppressWarnings(ggdag::dag_adjustment_sets(x))
adjusted_for <- attributes(x)$adjusted

# if we have multiple sets, we only need one for the current model
if (!is.null(p1$data$set) && insight::n_unique(p1$data$set) > 1) {
p1$data <- p1$data[p1$data$set == p1$data$set[1], ]
# rename set-variables
p2$data$set <- gsub("\\{(.*)\\}", "\\1", p2$data$set)
p2$data$set <- paste0("Adjusted for ", p2$data$set)
}

# for current plot, we need to update the "adjusted" column
p1$data$adjusted <- "unadjusted"
if (!is.null(adjusted_for)) {
Expand Down Expand Up @@ -142,6 +150,15 @@ plot.see_check_dag <- function(x,
common_layers +
ggplot2::ggtitle("Required model")

# if we have multiple sets, we want to facet the second plot by sets
if (!is.null(p2$data$set) && insight::n_unique(p2$data$set) > 1) {
plot2 <- plot2 + ggplot2::facet_wrap(
~set,
scales = "free",
ncol = ceiling(sqrt(insight::n_unique(p2$data$set)))
)
}

if (which == "all") {
# fix legends - remove the legend that has fewer items, so all items
# in the legend are shown for the integrated plot
Expand Down
Loading
Loading