mermaid_rmd {pedMermaid} | R Documentation |
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.
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 ( 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 ( RoundBorder : Child (corresponding to ID) node's border shape (90 DashBorder : Child (corresponding to ID) node's border line style (dashed vs solid).
This column receives lwd : Child (corresponding to ID) node's border line width.
This column receives values > 0, |
orient |
: Defines the orientation of the flowchart ( |
type |
: Defines the type of links in the flowchart ( |
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)