Package 'pedMermaid'

Title: Pedigree Mermaid Syntax
Description: Generate Mermaid syntax for a pedigree flowchart from a pedigree data frame. Mermaid syntax is commonly used to generate plots, charts, diagrams, and flowcharts. It is a textual syntax for creating reproducible illustrations. This package generates Mermaid syntax from a pedigree data frame to visualize a pedigree flowchart. The Mermaid syntax can be embedded in a Markdown or R Markdown file, or viewed on Mermaid editors and renderers. Links' shape, style, and orientation can be customized via function arguments, and nodes' shapes and styles can be customized via optional columns in the pedigree data frame.
Authors: Mohammad Ali Nilforooshan [aut, cre]
Maintainer: Mohammad Ali Nilforooshan <[email protected]>
License: GPL (>= 3)
Version: 1.0.2
Built: 2024-11-15 05:52:51 UTC
Source: https://github.com/nilforooshan/pedmermaid

Help Index


Generate Mermaid syntax for a pedigree flowchart in Markdown

Description

Generate Mermaid syntax for a pedigree flowchart in Markdown

Usage

mermaid_md(
  ped,
  orient = "TB",
  type = "arrow",
  curve = "basis",
  dash = "N",
  lwd = 2,
  color = "black"
)

Arguments

ped

: A data frame with the mandatory columns ID, SIRE, and DAM, and the optional columns TextColor, BgColor, BorderColor, RoundBorder, DashBorder, and lwd. The optional columns define (child) node-specific shape and style (corresponding to the ID column). The order of columns does not matter, but column names do matter and case-sensitive.

ped columns:

ID : Numeric or alphanumeric individual identifications.

SIRE : Sire identifications. Missing sires are denoted as 0.

DAM : Dam identifications. Missing dams are denoted as 0.

TextColor : Child (corresponding to ID) node's text color (valid color names and valid hex color codes). If this column is missing, the default color ("black" or "#000000") is used. Also, NA enforces the default color.

BgColor : Child (corresponding to ID) node's background color (valid color names and valid hex color codes). If this column is missing, the default color ("#ECECFF") is used. Also, NA enforces the default color.

BorderColor : Child (corresponding to ID) node's border color (valid color names and valid hex color codes). If this column is missing, the default color ("#9370DB") is used. Also, NA enforces the default color.

RoundBorder : Child (corresponding to ID) node's border shape (90\circ vs rounded edges). This column receives "Y" (rounded edges), "N" (90\circ edges), and NA (equivalent to the default value). If this column is missing, the default border shape ("N") is used.

DashBorder : Child (corresponding to ID) node's border line style (dashed vs solid). This column receives "Y" (solid line), "N" (dashed line), and NA (equivalent to the default value). If this column is missing, the default border line style ("N") is used.

lwd : Child (corresponding to ID) node's border line width. This column receives values > 0, \leq 5, and NA (equivalent to the default value). If this column is missing, the default value (1) is used.

orient

: Defines the orientation of the flowchart ("TB" for top-to-bottom vs "LR" for left-to-right). If no input is provided, the default orientation ("TB") is used.

type

: Defines the type of links in the flowchart ("arrow" vs "line"). If no input is provided, the default link type ("arrow") is used.

curve

: Defines the shape of links in the flowchart ("basis", "bumpX", "bumpY", "cardinal", "catmullRom", "linear", "monotoneX", "monotoneY", "natural", "step", "stepAfter", and "stepBefore"). If no input is provided, the default link shape ("basis") is used.

dash

: Defines the style of links in the flowchart ("N" for solid line vs "Y" for dashed line). If no input is provided, the default link style ("N") is used.

lwd

: Defines the width of links in the flowchart (> 0 and \leq 5). If no input is provided, the default value (2) is used.

color

: Defines the color of links in the flowchart (a valid color name or a valid hex color code). If no input is provided, the default color ("black" or "#000000") is used.

Value

: A vector of character strings. Each character string is a Mermaid syntax line. Assuming the returned output is saved in object x, use cat(x, sep = "\n") to display the output on-screen, and cat(x, sep = "\n", file = "output.txt") or write(x, file = "output.txt") to write the output into a file.

Examples

# A sample pedigree data frame with only the three mandatory columns.
ped <- data.frame(ID = 1:7, SIRE = c(0, 0, 1, 0, 3, 0, 5), DAM = c(0, 0, 2, 2, 4, 0, 6))

# Example 1: A pedigree Mermaid syntax without customizations.
x <- mermaid_md(ped)
# Read the "Value" part about displaying the output on-screen and writing it into a file.

# Example 2: Repeat example 1. Change arrow links to lines and the orientation to horizontal.
x <- mermaid_md(ped, orient = "LR", type = "line")

# Example 3: Repeat example 1. Pink background and round border edges for females (2, 4, 6).
ped$BgColor <- c(NA, "pink", NA, "pink", NA, "pink", NA)
ped$RoundBorder <- c(NA, "Y", NA, "Y", NA, "Y", NA)
x <- mermaid_md(ped)

# Example 4: Repeat example 3. Ticker border line for individuals in the control group (2, 5, 7).
ped$lwd <- c(1, 3, 1, 1, 3, 1, 3)
x <- mermaid_md(ped)

# Example 5: Use the default value and NA alternatively. This is not different from example 4.
ped$lwd <- c(NA, 3, NA, NA, 3, NA, 3)
x <- mermaid_md(ped)

# Example 6: Repeat example 1. Change link curve to "step" and green dashed.
x <- mermaid_md(ped[, c("ID", "SIRE", "DAM")],
    curve = "step", color = "#00FF00", dash = "Y")

Generate Mermaid syntax for a pedigree flowchart in Markdown & R Markdown

Description

Generate Mermaid syntax for a pedigree flowchart in Markdown & R Markdown

Usage

mermaid_rmd(ped, orient = "TB", type = "arrow")

Arguments

ped

: A data frame with the mandatory columns ID, SIRE, and DAM, and the optional columns BgColor, BorderColor, RoundBorder, DashBorder, and lwd. The optional columns define (child) node-specific shape and style (corresponding to the ID column). The order of columns does not matter, but column names do matter and case-sensitive.

ped columns:

ID : Numeric or alphanumeric individual identifications.

SIRE : Sire identifications. Missing sires are denoted as 0.

DAM : Dam identifications. Missing dams are denoted as 0.

BgColor : Child (corresponding to ID) node's background color (valid color names and valid hex color codes). If this column is missing, the default color ("#ECECFF") is used. Also, NA enforces the default color.

BorderColor : Child (corresponding to ID) node's border color (valid color names and valid hex color codes). If this column is missing, the default color ("#9370DB") is used. Also, NA enforces the default color.

RoundBorder : Child (corresponding to ID) node's border shape (90\circ vs rounded edges). This column receives "Y" (rounded edges), "N" (90\circ edges), and NA (equivalent to the default value). If this column is missing, the default border shape ("N") is used.

DashBorder : Child (corresponding to ID) node's border line style (dashed vs solid). This column receives "Y" (solid line), "N" (dashed line), and NA (equivalent to the default value). If this column is missing, the default border line style ("N") is used.

lwd : Child (corresponding to ID) node's border line width. This column receives values > 0, \leq 5, and NA (equivalent to the default value). If this column is missing, the default value (1) is used.

orient

: Defines the orientation of the flowchart ("TB" for top-to-bottom vs "LR" for left-to-right). If no input is provided, the default orientation ("TB") is used.

type

: Defines the type of links in the flowchart ("arrow" vs "line"). If no input is provided, the default link type ("arrow") is used.

Details

The Mermaid syntax generated by the mermaid_md function can be embeded in Markdown files and Markdown renderes such as GitHub, but not in R Markdown. Currently, Mermaid flowcharts in R Markdown have more limitations in terms of shape and style customizations, and the required syntax is less compact. Note that the generated syntax by this function can be embeded in both R Markdown and Markdown.

Value

: A vector of character strings. Each character string is a Mermaid syntax line. Assuming the returned output is saved in object x, use cat(x, sep = "\n") to display the output on-screen, and cat(x, sep = "\n", file = "output.txt") or write(x, file = "output.txt") to write the output into a file.

Examples

# A sample pedigree data frame with only the three mandatory columns.
ped <- data.frame(ID = 1:7, SIRE = c(0, 0, 1, 0, 3, 0, 5), DAM = c(0, 0, 2, 2, 4, 0, 6))

# Example 1: A pedigree Mermaid syntax without customizations.
x <- mermaid_rmd(ped)
# Read the "Value" part about displaying the output on-screen and writing it into a file.

# Example 2: Repeat example 1. Change arrow links to lines and the orientation to horizontal.
x <- mermaid_rmd(ped, orient = "LR", type = "line")

# Example 3: Repeat example 1. Pink background and round border edges for females (2, 4, 6).
ped$BgColor <- c(NA, "pink", NA, "pink", NA, "pink", NA)
ped$RoundBorder <- c(NA, "Y", NA, "Y", NA, "Y", NA)
x <- mermaid_rmd(ped)

# Example 4: Repeat example 3. Ticker border line for individuals in the control group (2, 5, 7).
ped$lwd <- c(1, 3, 1, 1, 3, 1, 3)
x <- mermaid_rmd(ped)

# Example 5: Use the default value and NA alternatively. This is not different from example 4.
ped$lwd <- c(NA, 3, NA, NA, 3, NA, 3)
x <- mermaid_rmd(ped)