Illustrating CFAs – Graphviz

December 9, 2010

(This article was first published on Sustainable Research » Renglish, and kindly contributed to R-bloggers)

So after yesterdays post you probably ran this fancy new confirmatory factor analysis (CFA) – showed your friends all the cool fit stats and… nothing.

As important as doing things right is being able to let others know that. For CFA the method of choice to illustrate the connections between variables are path diagrams these are best generated using graphviz.

The example above is generated by the following code:

digraph HSCFA {

Factor_1 -> y1 [weight=1000, label=”0.80″];

Factor_1 -> y2 [weight=1000, label=”0.80″];

Factor_1 -> y3 [weight=1000, label=”0.80″];

Factor_1 -> y4 [weight=1000, label=”0.80″];

Factor_2 -> y5 [weight=1000, label=”0.80″];

Factor_2 -> y6 [weight=1000, label=”0.80″];

Factor_2 -> y7 [weight=1000, label=”0.80″];

Factor_2 -> y8 [weight=1000, label=”0.80″];

Factor_1->Factor_2 [dir=both”];

y1 [shape=box,group=”obsvar”];

y2 [shape=box,group=”obsvar”];

y3 [shape=box,group=”obsvar”];

y4 [shape=box,group=”obsvar”];

y5 [shape=box,group=”obsvar”];

y6 [shape=box,group=”obsvar”];

y7 [shape=box,group=”obsvar”];

y8 [shape=box,group=”obsvar”];

{ rank = same; y1; y2; y3; y4; y5; y6; y7; y8}

{ rank = same; Factor_2; Factor_1; }

{ rank = max; d1; d2; d3; d4; d5; d6; d7; d8}

d1 -> y1;

d1 [shape=plaintext,label=””];

d2 -> y2;

d2 [shape=plaintext,label=””];

d3 -> y3;

d3 [shape=plaintext,label=””];

d4 -> y4;

d4 [shape=plaintext,label=””];

d5 -> y5;

d5 [shape=plaintext,label=””];

d6 -> y6;

d6 [shape=plaintext,label=””];

d7 -> y7;

d7 [shape=plaintext,label=””];

d8 -> y8;

d8 [shape=plaintext,label=””];


This looks like a lot to draw such a simple diagram, but please believe me not having to adjust these item labels or try to generate a file with a decent resolution that you can sent your publisher, can also take you a day or two…
More complex exmples can be found here.

If you are using the sem package to fit the SEM, you can generate the code for graphviz that will plot the model with standardized estimates detailed in this post.

To leave a comment for the author, please follow the link and comment on their blog: Sustainable Research » Renglish. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)