Skip to content

Commit

Permalink
Merge pull request #161 from r-causal/tidyup
Browse files Browse the repository at this point in the history
Tidy up a little
  • Loading branch information
malcolmbarrett authored Jul 22, 2024
2 parents ef31d5f + 4eeb506 commit 46d7ca8
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 913 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Description: Tidy, analyze, and plot directed acyclic graphs (DAGs).
'ggplot2' and 'ggraph', as well as common analytic and graphical
functions, such as determining adjustment sets and node relationships.
License: MIT + file LICENSE
URL: https://github.com/r-causal/ggdag,
https://r-causal.github.io/ggdag/
URL: https://github.com/r-causal/ggdag, https://r-causal.github.io/ggdag/
BugReports: https://github.com/r-causal/ggdag/issues
Depends:
R (>= 3.4.0)
Expand Down Expand Up @@ -42,8 +41,8 @@ Suggests:
withr
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Config/testthat/edition: 3
98 changes: 48 additions & 50 deletions R/adjustment_sets.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,31 @@ extract_sets <- function(sets) {
#' @rdname adjustment_sets
#' @export
ggdag_adjustment_set <- function(
.tdy_dag,
exposure = NULL,
outcome = NULL,
...,
shadow = TRUE,
size = 1,
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 10,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
label = NULL,
text = NULL,
node = deprecated(),
stylized = deprecated(),
expand_x = expansion(c(0.25, 0.25)),
expand_y = expansion(c(0.2, 0.2))
) {
.tdy_dag,
exposure = NULL,
outcome = NULL,
...,
shadow = TRUE,
size = 1,
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 10,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
label = NULL,
text = NULL,
node = deprecated(),
stylized = deprecated(),
expand_x = expansion(c(0.25, 0.25)),
expand_y = expansion(c(0.2, 0.2))) {
.tdy_dag <- if_not_tidy_daggity(.tdy_dag) %>%
dag_adjustment_sets(exposure = exposure, outcome = outcome, ...)

Expand Down Expand Up @@ -223,30 +222,29 @@ adjust_for <- control_for
#' @rdname control_for
#' @export
ggdag_adjust <- function(
.tdy_dag,
var = NULL,
...,
size = 1,
edge_type = c("link_arc", "link", "arc", "diagonal"),
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 10,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
text = NULL,
label = NULL,
node = deprecated(),
stylized = deprecated(),
collider_lines = TRUE
) {
.tdy_dag,
var = NULL,
...,
size = 1,
edge_type = c("link_arc", "link", "arc", "diagonal"),
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 10,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
text = NULL,
label = NULL,
node = deprecated(),
stylized = deprecated(),
collider_lines = TRUE) {
.tdy_dag <- if_not_tidy_daggity(.tdy_dag, ...)
if (!is.null(var)) {
.tdy_dag <- .tdy_dag %>% control_for(var)
Expand Down
35 changes: 17 additions & 18 deletions R/canonical.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ node_canonical <- function(.dag, ...) {
#' @rdname canonicalize
#' @export
ggdag_canonical <- function(
.tdy_dag,
...,
edge_type = "link_arc",
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = text_col,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = NULL,
label = NULL,
text = NULL,
node = deprecated(),
stylized = deprecated()
) {
.tdy_dag,
...,
edge_type = "link_arc",
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = text_col,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = NULL,
label = NULL,
text = NULL,
node = deprecated(),
stylized = deprecated()) {
if_not_tidy_daggity(.tdy_dag, ...) %>%
node_canonical() %>%
ggdag(
Expand Down
43 changes: 21 additions & 22 deletions R/colliders.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,27 @@ node_collider <- function(.dag, as_factor = TRUE, ...) {
#' @rdname colliders
#' @export
ggdag_collider <- function(
.tdy_dag,
...,
size = 1,
edge_type = c("link_arc", "link", "arc", "diagonal"),
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 8,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
text = NULL,
label = NULL,
node = deprecated(),
stylized = deprecated()
) {
.tdy_dag,
...,
size = 1,
edge_type = c("link_arc", "link", "arc", "diagonal"),
node_size = 16,
text_size = 3.88,
label_size = text_size,
text_col = "white",
label_col = "black",
edge_width = 0.6,
edge_cap = 8,
arrow_length = 5,
use_edges = TRUE,
use_nodes = TRUE,
use_stylized = FALSE,
use_text = TRUE,
use_labels = FALSE,
text = NULL,
label = NULL,
node = deprecated(),
stylized = deprecated()) {
p <- if_not_tidy_daggity(.tdy_dag, ...) %>%
node_collider() %>%
dplyr::mutate(colliders = forcats::fct_rev(colliders)) %>%
Expand Down
Loading

0 comments on commit 46d7ca8

Please sign in to comment.