Skip to content

Commit

Permalink
Add tests, allow to plot specific effect
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Aug 12, 2024
1 parent 52a0f0d commit 00c48d3
Show file tree
Hide file tree
Showing 17 changed files with 1,217 additions and 9 deletions.
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.5
Version: 0.8.5.6
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
10 changes: 7 additions & 3 deletions R/plot.check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#' `"all"`, `"current"` or `"required"`.
#' @param check_colliders Logical indicating whether to highlight colliders.
#' Set to `FALSE` if the algorithm to detect colliders is very slow.
#' @param ... Not used.
#' @param effect Character string indicating which effect for the required model
#' is to be estimated. Can be either `"total"` or `"direct"`.
#' @param ... Currently not used.
#'
#' @return A ggplot2-object.
#'
Expand Down Expand Up @@ -55,14 +57,16 @@ plot.see_check_dag <- function(x,
size_text = 4.5,
colors = NULL,
which = "all",
effect = "total",
check_colliders = TRUE,
...) {
.data <- NULL
insight::check_if_installed(c("ggdag", "ggplot2"))
which <- match.arg(which, choices = c("all", "current", "required"))
effect <- match.arg(effect, choices = c("total", "direct"))

# get plot data
p1 <- p2 <- suppressWarnings(ggdag::dag_adjustment_sets(x))
p1 <- p2 <- suppressWarnings(ggdag::dag_adjustment_sets(x, effect = effect))
adjusted_for <- attributes(x)$adjusted

# if we have multiple sets, we only need one for the current model
Expand Down Expand Up @@ -148,7 +152,7 @@ plot.see_check_dag <- function(x,
# plot2 - required model
plot2 <- ggplot2::ggplot(p2$data, ggplot2::aes(x = .data$x, y = .data$y)) +
common_layers +
ggplot2::ggtitle("Required model")
ggplot2::ggtitle(sprintf("Required model (%s effect)", effect))

# 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) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions tests/testthat/_snaps/plot.check_dag/plot-check-dag-direct4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 00c48d3

Please sign in to comment.