toGraphviz {abn} R Documentation

## Convert a DAG into graphviz format

### Description

Given a matrix defining a DAG create a text file suitable for plotting with graphviz.

### Usage

toGraphviz(dag,
data.df=NULL,
data.dists=NULL,
group.var=NULL,
outfile=NULL,
directed=TRUE,
verbose=FALSE)


### Arguments

 dag a matrix defining a DAG. data.df a data frame containing the data used for learning the network. data.dists a list with named arguments matching the names of the data frame which gives the distribution family for each variable. See fitAbn for details. group.var only applicable for mixed models and gives the column name in data.df of the grouping variable (which must be a factor denoting group membership). See fitAbn for details. outfile a character string giving the filename which will contain the graphviz graph. directed logical; if TRUE, a directed acyclic graph is produced, otherwise an undirected graph. verbose if TRUE more output is printed. If TRUE and 'outfile=NULL' the '.dot' file is printed to console.

### Details

Graphviz (https://www.graphviz.org) is a visualisation software developed by AT&T and freely available. This function creates a text representation of the DAG, or the undirected graph, so this can be plotted using graphviz. The R package, Rgraphviz (available through the Bioconductor project https://www.bioconductor.org/) interfaces R and the working installation of graphviz.

Binary nodes will appear as squares, Gaussian as ovals and Poisson nodes as diamonds in the resulting graphviz network diagram. There are many other shapes possible for nodes and numerous other visual enhancements - see online graphviz documentation.

Bespoke refinements can be added by editing the raw outfile produced. For full manual editing, particularly of the layout, or adding annotations, one easy solution is to convert a postscript format graph (produced in graphviz using the -Tps switch) into a vector format using a tool such as pstoedit (http://www.pstoedit.net/), and then edit using a vector drawing tool like xfig. This can then be resaved as postscript or pdf thus retaining full vector quality.

### Value

Nothing is returned, but a file outfile written.

### Author(s)

Fraser Iain Lewis

Marta Pittavino

### Examples

## On a typical linux system the following code constructs a nice
## looking pdf file 'graph.pdf'.
## Not run:
## Subset of a build-in dataset
mydat <- ex0.dag.data[,c("b1","b2","b3","g1","b4","p2","p4")]

## setup distribution list for each node
mydists <- list(b1="binomial", b2="binomial", b3="binomial",
g1="gaussian", b4="binomial", p2="poisson",
p4="poisson")
## specify DAG model
mydag <- matrix(c(   0,1,0,0,1,0,0, #
0,0,0,0,0,0,0, #
0,1,0,0,1,0,0, #
1,0,0,0,0,0,1, #
0,0,0,0,0,0,0, #
0,0,0,1,0,0,0, #
0,0,0,0,1,0,0  #
), byrow=TRUE, ncol=7)

colnames(mydag) <- rownames(mydag) <- names(mydat)

## create file for processing with graphviz
outfile <- paste(tempdir(), "graph.dot", sep="/")
toGraphviz(dag=mydag, data.df=mydat, data.dists=mydists, outfile=outfile)
## and then process using graphviz tools e.g. on linux
if(Sys.info()[["sysname"]] == "Linux" && interactive()) {
system(paste( "dot -Tpdf -o graph.pdf", outfile))
system("evince graph.pdf")
}
## Example using data with a group variable  where b1<-b2
mydag <- matrix(c(0,1, 0,0), byrow=TRUE, ncol=2)

colnames(mydag) <- rownames(mydag) <- names(ex3.dag.data[,c(1,2)])
## specific distributions
mydists <- list(b1="binomial", b2="binomial")

## create file for processing with graphviz
outfile <- paste0(tempdir(), "/graph.dot")
toGraphviz(dag=mydag, data.df=ex3.dag.data[,c(1,2,14)], data.dists=mydists,
group.var="group",
outfile=outfile, directed=FALSE)
## and then process using graphviz tools e.g. on linux:
if(Sys.info()[["sysname"]] == "Linux" && interactive()) {
pdffile <- paste0(tempdir(), "/graph.pdf")
system(paste("dot -Tpdf -o ", pdffile, outfile))
system(paste("evince ", pdffile, " &"))   ## or some other viewer
}

## End(Not run)


[Package abn version 3.0.4 Index]
{"ft_lang_label":"__label__en","ft_lang_prob":0.68301827,"math_prob":0.85630333,"size":3732,"snap":"2023-40-2023-50","text_gpt3_token_len":1058,"char_repetition_ratio":0.12070815,"word_repetition_ratio":0.047244094,"special_character_ratio":0.2864416,"punctuation_ratio":0.21649484,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9870059,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-10T17:26:26Z\",\"WARC-Record-ID\":\"<urn:uuid:929d929c-d7ce-44d6-ac2b-78d79e8db0eb>\",\"Content-Length\":\"6777\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4fa95dc7-a056-4774-a19b-4949f661182b>\",\"WARC-Concurrent-To\":\"<urn:uuid:595fa115-b6e2-41b9-9bc7-6894b1f9ed75>\",\"WARC-IP-Address\":\"137.208.57.46\",\"WARC-Target-URI\":\"https://search.r-project.org/CRAN/refmans/abn/html/toGraphviz.html\",\"WARC-Payload-Digest\":\"sha1:5RH2ZMOVKMODQQU5PKTOYB5FA3EVECIJ\",\"WARC-Block-Digest\":\"sha1:EC7HDADXTGUXGZ3F6T7FZUHRWHSCEXBJ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679102612.80_warc_CC-MAIN-20231210155147-20231210185147-00544.warc.gz\"}"}