49
$\begingroup$

I am searching for [free] software that can produce nice looking graphical models, e.g.

enter image description here

Any suggestions would be appreciated.

$\endgroup$
  • 1
    $\begingroup$ You mean drawing pictures like this you linked or drawing ready models from some other software? If the latter, from which? $\endgroup$ – user88 Oct 9 '11 at 17:57
  • $\begingroup$ Drawing pictures liked the one I linked $\endgroup$ – C. Reed Oct 9 '11 at 18:30
  • 2
    $\begingroup$ It was created manually in Inkscape, so you can try doing the same. $\endgroup$ – user88 Oct 9 '11 at 20:06
  • 9
    $\begingroup$ That's awesome - the picture you provide is one I drew for Wikipedia in 2008, and I found this question when I was figuring out how to redraw it in 2012. You provide a PNG, but it was originally an SVG. Back then, I used Inkscape and it was terrible - I had to hand edit the SVG to add in the greek letters, because it couldn't handle it back then (maybe it still can't). I don't recommend it for anyone. I'm going to give the tikz approach a shot. $\endgroup$ – Bkkbrad Jul 13 '12 at 1:05
  • $\begingroup$ When I said I don't recommend it for anyone, I meant I don't recommend Inkscape for anyone trying to draw multiple consistent plate diagrams. $\endgroup$ – Bkkbrad Jul 13 '12 at 1:11

13 Answers 13

33
$\begingroup$

I currently have a similar problem (drawing multiple path diagrams for my dissertation), and so I was examining many of the options listed here already to draw similar diagrams. Many of the listed resources for drawing such vector graphics (such as in microsoft office or google drawings) can produce really nice path diagrams, with fairly minimal effort. But, part of the reason I was unsatisfied with such programs is that I needed to produce many diagrams, with only fairly minor changes between each diagram (e.g. add another node, change a label). The point and click vector graphics tools aren't well suited for this, and take more effort than need be to make such minor changes. Also it becomes difficult to maintain a template between many drawings. So, I decided to examine options to produce such graphics programattically.

Graphviz, as was already mentioned by thias, came really close to having all the bells and whistles I wanted for my graphics (as well as quite simple code to produce them), but it fell short for my needs in two ways; 1) mathematical fonts are lacking (e.g. I'm not sure if you can label a node with the $\beta$ symbol in Graphviz, 2) curved lines are hard to draw (see this post on drawing path diagrams using Graphviz on @Stask's website). Because of these limitations I have currently settled (very happily) on using the Tikz/pgf drawing library in Latex. An example is below of my attempt at reproducing your graphic (the biggest pain was the labels in the lower right corners of the boxes!);

enter image description here

\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 10mm, thick, draw =black!80, node distance = 16mm]
\tikzstyle{connect}=[-latex, thick]
\tikzstyle{box}=[rectangle, draw=black!100]
  \node[main, fill = white!100] (alpha) [label=below:$\alpha$] { };
  \node[main] (theta) [right=of alpha,label=below:$\theta$] { };
  \node[main] (z) [right=of theta,label=below:z] {};
  \node[main] (beta) [above=of z,label=below:$\beta$] { };
  \node[main, fill = black!10] (w) [right=of z,label=below:w] { };
  \path (alpha) edge [connect] (theta)
        (theta) edge [connect] (z)
		(z) edge [connect] (w)
		(beta) edge [connect] (w);
  \node[rectangle, inner sep=0mm, fit= (z) (w),label=below right:N, xshift=13mm] {};
  \node[rectangle, inner sep=4.4mm,draw=black!100, fit= (z) (w)] {};
  \node[rectangle, inner sep=4.6mm, fit= (z) (w),label=below right:M, xshift=12.5mm] {};
  \node[rectangle, inner sep=9mm, draw=black!100, fit = (theta) (z) (w)] {};
\end{tikzpicture}
\end{figure}
\end{document}
%note - compiled with pdflatex

Now, I am already writing up my dissertation in Latex, so if you just want the image without having to compile a whole Latex document it is slightly inconveniant, but there are some fairly minor workarounds to produce an image more directly (see this question over on stackoverflow). There are a host of other benifits to using Tikz for such a project though

  • Extensive documentation. The pgf manual holds your hand through making some similar diagrams. And once you get your feet wet...
  • A huge library of examples is there to demonstrate how to produce a huge variety of graphics.
  • And finally, the Tex stack exchange site is a good place to ask any questions about Tikz. They have some wizzes over there making some pretty fancy graphics (check out their blog for some examples).

At this time I have not considered some of the libraries for drawing the diagrams in the statistical package R directly from the specified models, but in the future I may consider them to a greater extent. There are some nice examples from the qgraph library for a proof of concept of what can be accomplished in R.

$\endgroup$
  • 1
    $\begingroup$ For those interested in drawing path diagrams for SEM (or for some more ideas about what can be accomplished in Microsoft Office products), I would suggest you check out Jeremy Mile's ppt file of path diagrams (at the bottom of the referenced webpage). $\endgroup$ – Andy W Oct 12 '11 at 12:31
  • 1
    $\begingroup$ Great response, it's a bit of a learning curve, but like anything TeX, I think it'll pay off in the long run. Thanks! $\endgroup$ – C. Reed Oct 16 '11 at 18:49
29
$\begingroup$

Laura Dietz has written a very nice library for tikz that enables drawing of Bayesian Networks in latex without needing to actually use tikz directly.

To demonstrate this package, see the following example for this question:

\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{figure}
  \centering
  \tikz{ %
    \node[latent] (alpha) {$\alpha$} ; %
    \node[latent, right=of alpha] (theta) {$\theta$} ; %
    \node[latent, right=of theta] (z) {z} ; %
    \node[latent, above=of z] (beta) {$\beta$} ; %
    \node[obs, right=of z] (w) {w} ; %
    \plate[inner sep=0.25cm, xshift=-0.12cm, yshift=0.12cm] {plate1} {(z) (w)} {N}; %
    \plate[inner sep=0.25cm, xshift=-0.12cm, yshift=0.12cm] {plate2} {(theta) (plate1)} {M}; %
    \edge {alpha} {theta} ; %
    \edge {theta} {z} ; %
    \edge {z,beta} {w} ; %
  }
\end{figure}
\end{document}
%note - compiled with pdflatex

enter image description here

While not exactly the same, it certainly conveys the same information and could be tweaked to better fit specific requirements. This package generates very acceptable figures without needing to learn the full tikz package.

$\endgroup$
  • 1
    $\begingroup$ This library is awesome! Greatly simplifies the creation of bayesian network diagrams! Thanks for sharing. $\endgroup$ – fccoelho Nov 20 '16 at 12:27
12
$\begingroup$

You can't beat http://daft-pgm.org/

Daft is a Python package that uses matplotlib to render pixel-perfect probabilistic graphical models for publication in a journal or on the internet. With a short Python script and an intuitive model-building syntax you can design directed (Bayesian Networks, directed acyclic graphs) and undirected (Markov random fields) models and save them in any formats that matplotlib supports (including PDF, PNG, EPS and SVG).

$\endgroup$
  • $\begingroup$ daft is awesome! this should be the accepted answer imho $\endgroup$ – dominik andreas Jun 12 '17 at 17:33
  • $\begingroup$ Daft has a few drawbacks: It doesn't autoscale the nodes to fit the text, doesn't calculate the layout of the network, etc. That was enought to turn me off. $\endgroup$ – fccoelho Jul 10 '17 at 18:23
7
$\begingroup$

You could try GraphViz.

This allows you to specify the graph in a text-file and it will be drawn automatically (avoiding overlapping arrows and so on). Go here (pdf) for a minimal example and a manual.

$\endgroup$
5
$\begingroup$

Inkscape is essentially a free version of Adobe Illustrator, and is a very strong program for doing vector graphics, like the picture you posted. It also plays rather nicely with most statistical packages for doing final edits/annotations/etc. to graphs - R, SAS, etc. can output a graph as a PDF or other vector format (like .eps), and then you can bring it in to Inkscape to mess about with colors, symbols, axis labels etc.

$\endgroup$
  • $\begingroup$ I prefer the tools that treat arrows as special objects: when I move the variables around, I hope the arrows will follow. It seems Inkscape cannot do this. $\endgroup$ – ziyuang Jun 18 '14 at 12:19
3
$\begingroup$

Dia is a free open source program for drawing diagrams. I find it useful and it's not too difficult to get started.

$\endgroup$
3
$\begingroup$

If you have a particular interest in using LaTeX, the LaTeXDraw program has some nice functionality for creating flow charts with embedded latex code.

It imports / exports PSTricks code and SVG, and can also export svg, pdf, eps, jpg, png, etc. It runs in Linux, Mac OS X, and Windows.

$\endgroup$
1
$\begingroup$

I have found Diagrammix to be a very flexible package, available for Mac OS X. It is a well rounded vector graphics package and does a good job at graphical models. It is fairly inexpensive and has some good add-ons that have helped improve the shapes and directions of edges.

$\endgroup$
  • $\begingroup$ A suggestion: you could show how to reproduce the graphical model in the question with Diagrammix like some answers did. $\endgroup$ – Firebug Nov 2 '16 at 16:32
-1
$\begingroup$

You could try Google Docs Draw. It looks like it will do what you want for free, right in your browser.

$\endgroup$
  • $\begingroup$ I have tried it, but (IMHO) it lacks Inkscape's flexibility. $\endgroup$ – suncoolsu Oct 10 '11 at 0:22
-1
$\begingroup$

You can go for PlantUML. It is open source and quite flexible.

$\endgroup$
-1
$\begingroup$

You can also use the Lucidchart webapp.

I've used it in the past for drawing graphs and it's free.

$\endgroup$
-1
$\begingroup$

SCAVIS has a Bayesian network. Try to google "scavis baysian network". The same program can draw different diagrams using Python (or Java) syntax.

$\endgroup$
-1
$\begingroup$

you can use draw.io and use one or their many templates to create these icons. It helps you create SVGs or any other format. and does not require you to install anything on your system.

$\endgroup$

protected by kjetil b halvorsen Jan 28 '18 at 15:31

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.