### Install ggdag Development Version from GitHub Source: https://github.com/r-causal/ggdag/blob/main/README.md Details how to install the development version of the ggdag R package directly from GitHub. This is useful for accessing the latest features or bug fixes. ```R # install.packages("devtools") devtools::install_github("r-causal/ggdag") ``` -------------------------------- ### Install ggdag R Package Source: https://github.com/r-causal/ggdag/blob/main/README.md Provides instructions for installing the ggdag R package from CRAN. This is the standard method for obtaining the latest stable release. ```R install.packages("ggdag") ``` -------------------------------- ### ggdag Example: Tidy DAG Analysis and Plotting Source: https://github.com/r-causal/ggdag/blob/main/README.md Demonstrates how to use the ggdag package to create, tidy, and plot causal DAGs. It shows integration with the dagitty package for DAG definition and ggplot2 for visualization, highlighting the tidy data format. ```R library(ggdag) library(ggplot2) # example from the dagitty package dag <- dagitty::dagitty("dag { y <- x <- z1 <- v -> z2 -> y z1 <- w1 <-> w2 -> z2 x <- w1 -> y x <- w2 -> y x [exposure] y [outcome] }") tidy_dag <- tidy_dagitty(dag) tidy_dag ``` -------------------------------- ### Create and Tidy DAG with dagify Source: https://github.com/r-causal/ggdag/blob/main/README.md Demonstrates creating a Directed Acyclic Graph (DAG) using R-like syntax with the `dagify` function and then tidying it for plotting with `tidy_dagitty`. This process defines nodes, edges, bidirected paths, exposure, and outcome. ```R tidy_ggdag <- dagify( y ~ x + z2 + w2 + w1, x ~ z1 + w1 + w2, z1 ~ w1 + v, z2 ~ w2 + v, w1 ~ ~w2, # bidirected path exposure = "x", outcome = "y" ) %>% tidy_dagitty() ``` -------------------------------- ### Initial Release and Core Functionality Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Marks the initial release of the ggdag package, establishing its core functionality for DAG visualization and analysis using ggplot2. ```R # ggdag 0.1.0 # Initial release of the ggdag package. ``` -------------------------------- ### Collider Path Activation and Node Equivalence Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Addresses bugs in functions related to activating collider paths and calculating node equivalent DAGs. These fixes improve the accuracy of path analysis and structural equivalence checks. ```APIDOC activate_collider_paths(dag, ...) - Activates collider paths in a DAG. - Fixes an error occurring when a collider had a high number of ancestors. - Parameters: - dag: The DAG object. - ...: Additional arguments. - Returns: The DAG with activated collider paths. node_equivalent_dags(dag, ...) - Calculates node equivalent DAGs. - Fixes an issue where extra columns were not joined to new tidy DAGs. - Parameters: - dag: The DAG object. - ...: Additional arguments. - Returns: DAGs that are equivalent in terms of node relationships. ``` -------------------------------- ### Path and Adjustment Set Functions Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Adds a 'limit' argument to functions related to DAG paths and adjustment sets, allowing users to control the number of paths or sets returned. This enhances flexibility in causal analysis. ```APIDOC dag_adjustment_sets(dag, ...) - Extracts adjustment sets from a DAG. - Parameters: - dag: The DAG object. - ...: Additional arguments, including 'width' for extraction. - Returns: A list or data frame of adjustment sets. dag_paths(dag, ...) - Calculates paths within a DAG. - Parameters: - dag: The DAG object. - limit: The maximum number of paths to return. - Returns: Information about paths. ggdag_paths(dag, ...) - Visualizes paths within a DAG using ggplot2. - Parameters: - dag: The DAG object. - limit: The maximum number of paths to visualize. - Returns: A ggplot object. ggdag_paths_fan(dag, ...) - Visualizes paths in a fan layout. - Parameters: - dag: The DAG object. - limit: The maximum number of paths to visualize. - Returns: A ggplot object. ``` -------------------------------- ### Basic DAG Plotting with ggdag Source: https://github.com/r-causal/ggdag/blob/main/README.md Plots a DAG object created by `tidy_dagitty` using the `ggdag` function. It applies a custom `theme_dag` for enhanced visualization. ```R ggdag(tidy_ggdag) + theme_dag() ``` -------------------------------- ### Collider Visualization and Character Handling Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Resolves issues in visualizing colliders and handling character data, ensuring correct aesthetic mapping and data processing for DAG plots. ```APIDOC ggdag_collider(dag, ...) - Visualizes collider structures in a DAG. - Fixes flipped aesthetics for colors vs. labels. - Parameters: - dag: The DAG object. - ...: Additional arguments. - Returns: A ggplot object. Use as.character.default() for character data. - Avoids dispatch errors when working with character vectors, especially when other packages are attached. ``` -------------------------------- ### Visualize Equivalent DAGs Source: https://github.com/r-causal/ggdag/blob/main/README.md Generates and plots equivalent Directed Acyclic Graphs (DAGs) using the `ggdag_equivalent_dags` function. It takes a DAG structure, such as a `confounder_triangle`, as input. ```R ggdag_equivalent_dags(confounder_triangle()) ``` -------------------------------- ### Ggraph and Node Equivalence Class Compatibility Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Addresses compatibility issues with ggraph 2.0.0 and fixes bugs in node equivalence class calculations, ensuring correct behavior for graph layouts and structural comparisons. ```APIDOC node_equivalent_class(dag, ...) - Calculates node equivalence classes. - Fixes join bugs related to DAG directionality and 'to' nodes. - Parameters: - dag: The DAG object. - ...: Additional arguments. - Returns: Information about node equivalence classes. Compatibility with ggraph 2.0.0: - Changed 'strength' parameter in curved geoms to maintain compatibility. ``` -------------------------------- ### General Bug Fixes and Deprecations Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Includes various bug fixes for common issues, addresses CRAN requirements, and deprecates certain arguments for cleaner API usage. This ensures package stability and adherence to best practices. ```APIDOC geom_dag_collider_edges(..., size = NULL, linewidth) - Deprecates the 'size' argument in favor of 'linewidth' for edge thickness. Fixed bugs in: - `dag_paths()` and `geom_dag_edges_fan()`. - `node_equivalent_class()` join logic. - `activate_collider_paths()` for colliders with many ancestors. - `node_equivalent_dags()` column joining. - `ggdag_collider()` aesthetic flipping. - `tidy_dagitty()` for nodes without edges. - `dag_adjustment_sets()` when 'width' option was low. - `left_join()` interface with dplyr 1.1.0. - Instrumental functions for complex/non-existent IVs. - Calculating and visualizing paths. - Compatibility with ggplot2 3.4.0. - CRAN errors and tidyverse changes. ``` -------------------------------- ### DAG Data Extraction and Update Utilities Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Adds functions to extract and update components of DAG objects, as well as to construct DAGs from data frames. These utilities facilitate data-driven DAG creation and manipulation. ```APIDOC pull_dag(dag, component) - Extracts a specific component (e.g., nodes, edges) from a DAG object. - Parameters: - dag: The DAG object. - component: The name of the component to extract. - Returns: The requested DAG component. pull_dag_data(dag, component) - Extracts data associated with a specific DAG component. - Parameters: - dag: The DAG object. - component: The name of the component. - Returns: Data frame of the component's data. update_dag(dag, component, new_data) - Updates a specific component of a DAG object with new data. - Parameters: - dag: The DAG object. - component: The component to update. - new_data: The new data for the component. - Returns: The updated DAG object. update_dag_data(dag, component, new_data) - Updates the data associated with a DAG component. - Parameters: - dag: The DAG object. - component: The component to update. - new_data: The new data. - Returns: The updated DAG object. as_tidy_dagitty(data, ...) - Constructs DAGs from data frames, often in a tidy format. - Parameters: - data: A data frame representing the DAG structure. - ...: Additional arguments for DAG construction. - Returns: A tidy dagitty object. ``` -------------------------------- ### Advanced DAG Plotting with ggplot2 Geoms Source: https://github.com/r-causal/ggdag/blob/main/README.md Illustrates advanced DAG visualization by combining `tidy_dagitty` with `ggplot2` geoms. It uses `node_dconnected` to highlight d-connected paths and customizes edges, points, and text. ```R dagify(m ~ x + y) %>% tidy_dagitty() %>% node_dconnected("x", "y", controlling_for = "m") %>% ggplot(aes( x = x, y = y, xend = xend, yend = yend, shape = adjusted, col = d_relationship )) + geom_dag_edges(end_cap = ggraph::circle(10, "mm")) + geom_dag_collider_edges() + geom_dag_point() + geom_dag_text(col = "white") + theme_dag() + scale_adjusted() + expand_plot(expand_y = expansion(c(0.2, 0.2))) + scale_color_viridis_d( name = "d-relationship", na.value = "grey85", begin = .35 ) ``` -------------------------------- ### Time-Ordered Coordinates and Layouts Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Implements automatic calculation of time-ordered coordinates and layout adjustments for DAGs. This feature aids in visualizing temporal relationships within causal structures. ```APIDOC time_ordered_coords(dag, ...) - Calculates time-ordered coordinates for nodes in a DAG. - Parameters: - dag: The DAG object. - ...: Additional arguments for coordinate calculation. - Returns: A data frame with time-ordered coordinates. layout(dag, layout_type, ...) - Applies a specified layout to a DAG, potentially time-ordered. - Parameters: - dag: The DAG object. - layout_type: The type of layout to apply (e.g., 'time_ordered'). - ...: Additional layout parameters. ``` -------------------------------- ### Plot Adjustment Set with ggdag Source: https://github.com/r-causal/ggdag/blob/main/README.md Visualizes the adjustment set for a given DAG using `ggdag_adjustment_set`. This function highlights nodes relevant for adjusting for confounding, with options for node size. ```R ggdag_adjustment_set(tidy_ggdag, node_size = 14) + theme(legend.position = "bottom") ``` -------------------------------- ### Conditional Independence Analysis Functions Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Introduces new functions for detecting, testing, and visualizing implied conditional independencies within a DAG and dataset. These functions enhance the package's capabilities for causal inference and graphical model analysis. ```APIDOC query_conditional_independence(dag, data) - Detects implied conditional independencies in a given DAG and dataset. - Parameters: - dag: A DAG object (e.g., from dagitty). - data: A data frame or tibble containing the dataset. - Returns: Information about conditional independencies. test_conditional_independence(dag, data) - Tests for conditional independencies in a given DAG and dataset. - Parameters: - dag: A DAG object. - data: A data frame or tibble. - Returns: Results of conditional independence tests. ggdag_conditional_independence(dag, data) - Visualizes implied conditional independencies in a given DAG and dataset. - Parameters: - dag: A DAG object. - data: A data frame or tibble. - Returns: A ggplot object visualizing conditional independencies. ``` -------------------------------- ### DAG Labeling and Text Geoms Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Introduces a new geom for adding labels to DAGs, complementing existing text and repel functions. This provides more options for annotating nodes within DAG visualizations. ```APIDOC geom_dag_label(mapping, data, ...) - Adds labels to DAG nodes using ggplot2. - Parameters: - mapping: Aesthetic mappings for labels. - data: The data frame containing node information. - ...: Additional arguments for label styling and placement. ``` -------------------------------- ### Manage Scales in ggdag (R) Source: https://github.com/r-causal/ggdag/blob/main/tests/testthat/_snaps/StatsandGeoms.md This R code snippet handles the addition and management of scales within the ggdag package. It checks for existing scales for the same aesthetics and provides informative messages if a scale is being replaced. It ensures that scales are correctly added or updated in the internal scales list. ```R if (is.null(scale)) { return() } prev_aes <- self$find(scale$aesthetics) if (any(prev_aes)) { scalename <- self$scales[prev_aes][[1]]$aesthetics[1] cli::cli_inform(c("Scale for {.field {scalename}} is already present.", "Adding another scale for {.field {scalename}}, which will replace the existing scale.")) } self$scales <- c(self$scales[!prev_aes], list(scale)) ``` -------------------------------- ### Visualize Butterfly Bias Source: https://github.com/r-causal/ggdag/blob/main/README.md Visualizes common bias structures, specifically the butterfly bias, using the `ggdag_butterfly_bias` function. This function allows customization of edge types, such as 'diagonal'. ```R ggdag_butterfly_bias(edge_type = "diagonal") ``` -------------------------------- ### DAG Layout Type Restriction Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Updates `tidy_dagitty()` to disallow the 'dendogram' layout type, enforcing more standard or appropriate layout options for DAGs. This change aims to prevent potentially misleading visualizations. ```APIDOC tidy_dagitty(dag, layout = "auto", ...) - Converts a dagitty object to a tidy format. - Parameters: - dag: A dagitty object. - layout: The layout algorithm to use. 'dendogram' is no longer supported. - ...: Additional arguments. - Returns: A tidy DAG object. ``` -------------------------------- ### ggplot2 Integration for DAGs Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Provides new functions to simplify the specification of ggplot code for DAGs, improving the ease of creating visualizations. These functions streamline the process of plotting DAG structures. ```APIDOC aes_dag(mapping, data, ...) - Simplifies the specification of aesthetics for DAG plots in ggplot2. - Parameters: - mapping: Aesthetic mappings (e.g., x, y, color). - data: The data frame for the DAG. - ...: Additional arguments passed to aes(). - Returns: An aesthetic mapping object. geom_dag(mapping, data, ...) - A geom for drawing DAGs using ggplot2. - Parameters: - mapping: Aesthetic mappings. - data: The data frame for the DAG. - ...: Additional arguments passed to geom_dag(). - Returns: A ggplot geom object for drawing DAGs. ``` -------------------------------- ### Repelled Label Geoms Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Introduces a new function for creating repelled labels that are optimized for DAG visualizations, aiming for better visual clarity and arrangement. This complements existing labeling functions. ```APIDOC geom_label_repel2(mapping, data, ...) - Creates repelled labels for DAG nodes, offering improved placement. - Parameters: - mapping: Aesthetic mappings for labels. - data: The data frame containing node information. - ...: Additional arguments for label repulsion and styling. - Returns: A ggplot geom object for repelled labels. ``` -------------------------------- ### Edge Geoms and ggplot2 Compatibility Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Fixes bugs in edge geoms and updates the use of ggplot2 functions for better compatibility with newer versions. This includes changes to expansion scales and edge drawing. ```APIDOC geom_dag_edges_fan(mapping, data, ...) - Draws edges in a fan layout for DAGs. - Fixes bugs related to edge drawing. - Parameters: - mapping: Aesthetic mappings for edges. - data: The data frame containing edge information. - ...: Additional arguments. - Returns: A ggplot geom object for drawing edges. Use ggplot2::expansion() instead of expand_scale() when ggplot2 version >= 3.3.0. - Ensures compatibility with ggplot2's updated scale expansion functions. ``` -------------------------------- ### Internal ggplot2 Dependency Management Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md ggdag now imports ggplot2 internally rather than listing it as a hard dependency. This change improves compatibility and reduces potential conflicts with other packages. ```R # Internal import of ggplot2 # library(ggplot2) is no longer called in NAMESPACE or DESCRIPTION # Instead, functions are accessed via ggplot2::function_name ``` -------------------------------- ### Legend Alignment for Scales Source: https://github.com/r-causal/ggdag/blob/main/NEWS.md Ensures that `scale_adjusted()` correctly aligns legend types, improving the consistency and readability of plots when using adjusted scales. ```APIDOC scale_adjusted(..., aesthetic = "colour") - Adjusts scales for DAG plots, ensuring proper legend alignment. - Parameters: - ...: Arguments passed to ggplot2 scales. - aesthetic: The aesthetic to adjust (e.g., 'colour', 'fill'). - Returns: A ggplot scale object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.