Produces text input for D2 to make a diagram of a given object, usually rendered with SVG.
d2(x, ...)
A scalar character, containing text input for D2.
an object to be plotted.
further arguments passed to or from other methods.
The D2 language is in an early stage of development (pre-v1.0), so it may be
subject to changes that make it unable to use output from the current version
of d2
.
Details of what is plotted are given in individual methods. There are expected commonalities, which are described below.
The object is expected to be one of the following:
an object whose elements have the same length. Examples would be data frames, matrices, and other objects that can represent relations, with names for the elements, and an optional name for the object itself.
a graph of sub-objects, each of which represent a relation as described above, possibly with connections between the objects, and an optional name for the graph as a whole.
Each relation is presented as a record-like shape, with the following elements:
A optional header with the relation's name, and the number of (unique) records.
A set of rows, one for each attribute in the relation. These rows have the following contents:
the attribute names.
a depiction of the relation's (candidate) keys. Each column represents a key, and a filled cell indicates that the attribute in that row is in that key. The keys are given in lexical order, with precedence given to keys with fewer attributes, and keys with attributes that appear earlier in the original data frame's attribute order. Default output from other package functions will thus have the primary key given first. In the future, this will be changed to always give the primary key first.
optionally, the attribute types: specifically, the first element
when passing the attribute's values into class
.
Any foreign key references between relations are represented by one-way arrows, one per attribute in the foreign key.
If the object has a name, then currently the name is not used, except as a single data frame's name. In the future, this will be used to give a name to the generated board, to make use of D2's composition features.
d2.data.frame
and d2.relation_schema
for
individual methods.
D2 language site: https://d2lang.com
Playground for running online without installation: https://play.d2lang.com/
Quarto extension: https://github.com/data-intuitive/quarto-d2
if (FALSE) {
# simple data.frame example
cat(d2(ChickWeight, "chick"))
}
Run the code above in your browser using DataLab