2
---
title: "Markdown Demo"
author: "J"
date: "6/14/2021"
output: html_document
---

## Setup
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DiagrammeR)
```

## R Markdown

```{r}

mermaid("
  graph TB;
    a ==> b; 
    b ----> c[apple]
    
                    
")
```

For some reason the 2nd line in the graph doesn't seem to be rendering because its not realizing the 'longer arrow'. Anyone know how to solve this trivial problem

user20650
  • 24,654
  • 5
  • 56
  • 91

1 Answers1

0

Looks like this depends on how large your network graph is. You can look up the documentation of the package in Rstudio by entering ??DiagrammeR::mermaid in the console.

An example from the package shows 10 nodes creates longer arrows than just A->B

Doesn't look like b ----> c[apple] is proper syntax for longer arrows, to what I read in the package docs.

grViz("
digraph a_nice_graph {

# node definitions with substituted label text
node [fontname = Helvetica]
a [label = '@@1']
b [label = '@@2-1']
c [label = '@@2-2']
d [label = '@@2-3']
e [label = '@@2-4']
f [label = '@@2-5']
g [label = '@@2-6']
h [label = '@@2-7']
i [label = '@@2-8']
j [label = '@@2-9']

# edge definitions with the node IDs
a -> {b c d e f g h i j}
}

[1]: 'top'
[2]: 10:20
")

enter image description here

Daniel_j_iii
  • 3,041
  • 2
  • 11
  • 27
  • 1
    I believe in your example your mixing up DiagrammeR::Graphviz with DiagrammeR::Mermaid which are different packages. In terms of the mermaid package, its possible so I'm not quite sure how to implement it into the R script. I've seen someone do it before with an older version of R. You can see that's its possible under the heading "Minimum length of a link" in the mermaid documentation. https://mermaid-js.github.io/mermaid/#/flowchart?id=links-between-nodes – Jordan Williams Jun 17 '21 at 15:10
  • Your code is telling me different, you loaded `library(DiagrammeR)` which loads the package into memory, and then you are calling the `mermaid` function within that package, hence the `package::function` syntax. But The link you posted is for Javascript and Markdown, unfortunately I am not a javascript person, I would suggest adding "javascript" tag to your question to see if you could get some Javascript devs to look at your question. – Daniel_j_iii Jun 17 '21 at 15:37