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 |
Generate Mermaid syntax for a pedigree flowchart in Markdown
mermaid_md( ped, orient = "TB", type = "arrow", curve = "basis", dash = "N", lwd = 2, color = "black" )
mermaid_md( ped, orient = "TB", type = "arrow", curve = "basis", dash = "N", lwd = 2, color = "black" )
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.
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 ( 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 ( |
curve |
: Defines the shape of links in the flowchart
( |
dash |
: Defines the style of links in the flowchart ( |
lwd |
: Defines the width of links in the flowchart (> 0 and |
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 ( |
: 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.
# 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")
# 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
mermaid_rmd(ped, orient = "TB", type = "arrow")
mermaid_rmd(ped, orient = "TB", type = "arrow")
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 ( |
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.
: 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.
# 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)
# 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)