giocomai / nomnomlgraph

Create `nomnoml` diagrams in R based on data frames with edges and nodes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nomnomlgraph

Lifecycle: experimental

The goal of nomnomlgraph is to enable the creation of basic diagrams such as those created with nomnoml without having to familiarise with its syntax.

To create a nomnoml diagram with nomnomlgraph you will need two data frames: one with nodes, the other with edges, in line with the structure of data tyipically used to generate network graphs.

This facilitates cooperation across teams with members that may be intimidated by nomnoml syntax and will feel at home in front of a spreadsheet, or even as a shared spreasheet on Google Drive.

Installation

You can install the development version of nomnomlgraph from GitHub:

# install.packages("remotes")
remotes::install_github("giocomai/nomnomlgraph")

or from R universe:

install.packages('nomnomlgraph', repos = c('https://giocomai.r-universe.dev', 'https://cloud.r-project.org'))

How to use

First, you will need a data frame with nodes:

library("nomnomlgraph")
nodes <- tibble::tribble(~id, ~text, 
                         1, "Starting point",
                         2, "Other starting point",
                         3, "This is where things merge",
                         4, "This is where things go")
knitr::kable(nodes)
id text
1 Starting point
2 Other starting point
3 This is where things merge
4 This is where things go

Then one with edges:

edges <- tibble::tribble(~from, ~to, ~association,
                         1, 3, "-", 
                         2, 3, "-",
                         3, 4, "->")

knitr::kable(edges)
from to association
1 3 -
2 3 -
3 4 ->

Et voilà:

nn_graph(nodes = nodes, 
         edges = edges)

To which you can add a bunch of customisations, see ?nn_graph() for details. E.g.

nn_graph(nodes = nodes, 
         edges = edges,
         fill = "#fdf6e3",
         edgesStyle = "rounded", 
         font = "Roboto Condensed",
         fillArrows = "true",
         svg = TRUE)

Something a bit more complex?

library("nomnomlgraph")
nodes <- tibble::tribble(~id, ~text, ~classifier,
                         1, "Partner X", "actor",
                         2, "Partner Y", "actor",
                         3, "Partner Z", "actor",
                         4, "Initiator", "sender",
                         5, "Do something together", "",
                         6, "Quality control", "choice", 
                         7, "Additional fixes", "", 
                         8, "Launch!", "transceiver")
knitr::kable(nodes)
id text classifier
1 Partner X actor
2 Partner Y actor
3 Partner Z actor
4 Initiator sender
5 Do something together
6 Quality control choice
7 Additional fixes
8 Launch! transceiver

Then one with edges:

edges <- tibble::tribble(~from, ~to, ~association,
                         4, 5, "-",
                         1, 5, "-", 
                         2, 5, "-",
                         3, 5, "-",
                         5, 6, "->",
                         6, 7, "No ->",
                         7, 6, "-->", 
                         6, 8, "Yes! ->")

knitr::kable(edges)
from to association
4 5 -
1 5 -
2 5 -
3 5 -
5 6 ->
6 7 No ->
7 6 –>
6 8 Yes! ->
nn_graph(nodes = nodes, 
         edges = edges,
         edgesStyle = "rounded", 
         font = "Roboto Condensed",
         svg = TRUE,
         width = 600,
         height = 300,
         )

Finalise on nomnoml.com

If you enable set the “output” parameter to “code”, you will get a chunk of text that you can paste directly on nomnoml.com for further adjustments.

nn_graph(nodes = nodes, 
         edges = edges,
         output = "code",
         edgesStyle = "rounded"
         ) |> 
  cat()
#direction: down
#edges: rounded
#lineWidth: 1
#fill: #FEFEFF
#zoom: 4
#arrowSize: 1
#bendSize: 0.3
#gutter: 5
#edgeMargin: 0
#fillArrows: false
#font: sans
#fontSize: 12
#leading: 1.25
#padding: 8
#spacing: 40
#stroke: #33322E
#title: filename

[<sender>Initiator]-[Do something together]
[<actor>Partner X]-[Do something together]
[<actor>Partner Y]-[Do something together]
[<actor>Partner Z]-[Do something together]
[Do something together]->[<choice>Quality control]
[<choice>Quality control]No ->[Additional fixes]
[Additional fixes]-->[<choice>Quality control]
[<choice>Quality control]Yes! ->[<transceiver>Launch!]

(remember to use cat() if you are copy/pasting it from the console to process the new lines)

More

For more details, see the documentation of the nomnoml package for R: https://github.com/rstudio/nomnoml/

The original nomnoml: https://nomnoml.com/

Licensing

This package is distributed under the MIT license.

About

Create `nomnoml` diagrams in R based on data frames with edges and nodes

License:Other


Languages

Language:R 100.0%