# hy4m/linket architecture

> Architecture diagram of the GitHub repository hy4m/linket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hy4m/linket
- Repository: https://github.com/hy4m/linket

## Overview

##### File structure
- Top level
- DESCRIPTION, NAMESPACE: package metadata and export directives
- README.Rmd / README.md: user guide and examples
- .Rbuildignore, .gitignore: build tooling
- R/ directory
- Core data‐wrangling: `matrix_data()`, `as_matrix_data()`, `as_md_tbl()`, utils-matrix-data.R, utils.R
- Statistical functions: `correlate()`, `mantel_test()`, `random_forest()`, `calc_relimp()`, `pvalue_adjust()`, `gdist()`
- Plotting API (high-level wrappers): `hyplot()`, `qcorrplot()`, `qpairs()`, `qlink()`
- Geom extensions (ggproto objects): dozens of `geom_*` (geom_doughnut, geom_square, geom_couple, etc.), scale_* and theme_* functions, layout and styling helpers
- Package hooks: zzz.R, deprecated/experimental stubs
- man/ directory
- Auto‐generated Rd files—one per exported function
- Figures used in README
- inst/
- CITATION template
- tests/
- testthat harness and individual tests (e.g. test_linkET.R)

##### Readme insights
- Describes workflow:
a) Data ingestion via matrix_data/as_md_tbl or as_* methods
b) Statistical transforms (correlate, mantel_test) yielding matrix‐style objects
c) High‐level plotting – hyplot + geoms, qcorrplot + geom_square, qpairs + geom_pairs
d) Custom styling via set_corrplot_style / set_default_style
e) Under the hood, everything is a ggplot2 extension built on ggproto

##### Detail
- Both runtime flow (data & plotting) and build flow (docs & tests)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main user
    User["User / Client Code"]:::user

    %% Infrastructure
    subgraph "Infrastructure" 
        Metadata["DESCRIPTION & NAMESPACE"]:::infra
        Docs["man/ & README"]:::infra
        Tests["tests/"]:::infra
        Citation["inst/CITATION"]:::infra
    end

    %% Data & Stats Modules
    subgraph "Data & Stats Modules" 
        direction TB
        subgraph "Data Module" 
            DM1["matrix_data()"]:::data
            DM2["as_matrix_data()"]:::data
            DM3["as_md_tbl()"]:::data
            DM4["utils_matrix_data.R"]:::data
            DM5["utils.R"]:::data
        end
        subgraph "Stats Module"
            SM1["correlate()"]:::stats
            SM2["mantel_test()"]:::stats
            SM3["random_forest()"]:::stats
            SM4["calc_relimp()"]:::stats
            SM5["pvalue_adjust()"]:::stats
            SM6["gdist()"]:::stats
            SM7["as_correlate()"]:::stats
            SM8["rand_correlate()"]:::stats
        end
    end

    %% Visualization API
    subgraph "Visualization API"
        direction TB
        API1["hyplot()"]:::api
        API2["qcorrplot()"]:::api
        API3["qlink()"]:::api
    end

    %% Geom Extensions
    subgraph "Geom Extensions"
        direction TB
        GE1["geom_annotate"]:::geom
        GE2["geom_corr"]:::geom
        GE3["geom_couple"]:::geom
        GE4["geom_curve2"]:::geom
        GE5["geom_diag_label"]:::geom
        GE6["geom_doughnut"]:::geom
        GE7["geom_magic_text"]:::geom
        GE8["geom_mark"]:::geom
        GE9["geom_panel_grid"]:::geom
        GE10["geom_shaping"]:::geom
        GE11["geom_square"]:::geom
        GE12["ggproto definitions"]:::geom
        GE13["scale_marker"]:::geom
        GE14["theme_hy"]:::geom
        GE15["layout"]:::geom
        GE16["marker"]:::geom
        GE17["network"]:::geom
        GE18["color_pal"]:::geom
        GE19["axis"]:::geom
        GE20["get_order"]:::geom
        GE21["reorder_by"]:::geom
    end

    %% External Dependencies
    External["External Deps\n(vegan, RColorBrewer, dplyr)"]:::external

    %% Core ggplot2
    GG["ggplot2 Core"]:::external

    %% Relationships
    User -->|"calls"| API1
    User -->|"calls"| API2
    User -->|"calls"| API3

    API1 -->|"ingest data"| DM1
    API1 --> DM2
    API1 --> DM3
    API1 -->|"stats transform"| SM1
    API1 --> SM2

    API2 --> DM1
    API2 --> SM1
    API2 --> GE11

    API3 --> DM1
    API3 --> SM1
    API3 --> GE3

    API1 -->|"register geoms"| GE1
    API1 --> GE2
    API1 --> GE3
    API1 --> GE4
    API1 --> GE5

    GE1 --> GG
    GE2 --> GG
    GE3 --> GG
    GE4 --> GG
    GE5 --> GG
    GE6 --> GG
    GE7 --> GG
    GE8 --> GG
    GE9 --> GG
    GE10 --> GG
    GE11 --> GG
    GE12 --> GG
    GE13 --> GG
    GE14 --> GG
    GE15 --> GG
    GE16 --> GG
    GE17 --> GG
    GE18 --> GG
    GE19 --> GG
    GE20 --> GG
    GE21 --> GG

    SM1 --> External
    SM2 --> External
    SM3 --> External
    SM4 --> External
    SM5 --> External
    SM6 --> External
    SM7 --> External
    SM8 --> External

    DM1 --> External
    DM2 --> External
    DM3 --> External
    DM4 --> External
    DM5 --> External

    %% Build flow
    Rfiles["R/ directory"]:::infra
    Rfiles -->|"roxygen2"| Docs
    Tests --> Rfiles

    %% Package metadata to docs
    Metadata --> Docs

    %% Click events Data Module
    click DM1 "https://github.com/hy4m/linket/blob/master/R/matrix-data.R"
    click DM2 "https://github.com/hy4m/linket/blob/master/R/as-matrix-data.R"
    click DM3 "https://github.com/hy4m/linket/blob/master/R/as-md-tbl.R"
    click DM4 "https://github.com/hy4m/linket/blob/master/R/utils-matrix-data.R"
    click DM5 "https://github.com/hy4m/linket/blob/master/R/utils.R"

    %% Click events Stats Module
    click SM1 "https://github.com/hy4m/linket/blob/master/R/correlate.R"
    click SM2 "https://github.com/hy4m/linket/blob/master/R/mantel-test.R"
    click SM3 "https://github.com/hy4m/linket/blob/master/R/random-forest.R"
    click SM4 "https://github.com/hy4m/linket/blob/master/R/calc-relimp.R"
    click SM5 "https://github.com/hy4m/linket/blob/master/R/pvalue-adjust.R"
    click SM6 "https://github.com/hy4m/linket/blob/master/R/gdist.R"
    click SM7 "https://github.com/hy4m/linket/blob/master/R/as-correlate.R"
    click SM8 "https://github.com/hy4m/linket/blob/master/R/rand-correlate.R"

    %% Click events API
    click API1 "https://github.com/hy4m/linket/blob/master/R/hyplot.R"
    click API2 "https://github.com/hy4m/linket/blob/master/R/qcorrplot.R"
    click API3 "https://github.com/hy4m/linket/blob/master/R/qlink.R"

    %% Click events Geom Extensions
    click GE1 "https://github.com/hy4m/linket/blob/master/R/geom-annotate.R"
    click GE2 "https://github.com/hy4m/linket/blob/master/R/geom-corr.R"
    click GE3 "https://github.com/hy4m/linket/blob/master/R/geom-couple.R"
    click GE4 "https://github.com/hy4m/linket/blob/master/R/geom-curve2.R"
    click GE5 "https://github.com/hy4m/linket/blob/master/R/geom-diag-label.R"
    click GE6 "https://github.com/hy4m/linket/blob/master/R/geom-doughnut.R"
    click GE7 "https://github.com/hy4m/linket/blob/master/R/geom-magic-text.R"
    click GE8 "https://github.com/hy4m/linket/blob/master/R/geom-mark.R"
    click GE9 "https://github.com/hy4m/linket/blob/master/R/geom-panel-grid.R"
    click GE10 "https://github.com/hy4m/linket/blob/master/R/geom-shaping.R"
    click GE11 "https://github.com/hy4m/linket/blob/master/R/geom-square.R"
    click GE12 "https://github.com/hy4m/linket/blob/master/R/ggproto.R"
    click GE13 "https://github.com/hy4m/linket/blob/master/R/scale-marker.R"
    click GE14 "https://github.com/hy4m/linket/blob/master/R/theme-hy.R"
    click GE15 "https://github.com/hy4m/linket/blob/master/R/layout.R"
    click GE16 "https://github.com/hy4m/linket/blob/master/R/marker.R"
    click GE17 "https://github.com/hy4m/linket/blob/master/R/network.R"
    click GE18 "https://github.com/hy4m/linket/blob/master/R/color-pal.R"
    click GE19 "https://github.com/hy4m/linket/blob/master/R/axis.R"
    click GE20 "https://github.com/hy4m/linket/blob/master/R/get-order.R"
    click GE21 "https://github.com/hy4m/linket/blob/master/R/reorder_by.R"

    %% Infrastructure clicks
    click Metadata "https://github.com/hy4m/linket/tree/master/DESCRIPTION"
    click Metadata "https://github.com/hy4m/linket/tree/master/NAMESPACE"
    click Docs "https://github.com/hy4m/linket/tree/master/man/"
    click Docs "https://github.com/hy4m/linket/blob/master/README.Rmd"
    click Tests "https://github.com/hy4m/linket/tree/master/tests/"
    click Citation "https://github.com/hy4m/linket/tree/master/inst/CITATION"

    %% Styles
    classDef user fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef data fill:#cfe2f3,stroke:#08529d,stroke-width:1px
    classDef stats fill:#dae8fc,stroke:#6c8ebf,stroke-width:1px
    classDef api fill:#fce5cd,stroke:#d79b00,stroke-width:1px
    classDef geom fill:#d5e8d4,stroke:#82b366,stroke-width:1px
    classDef infra fill:#e0e0e0,stroke:#888888,stroke-width:1px
    classDef external fill:#fff2cc,stroke:#bf9000,stroke-width:1px
```
