One of my main projects at Charles University involves path analysis. A problem I came up against in my PhD work was with finding a time-efficient way to draw multiple path diagrams. I didn't put too much effort into finding a solution back then and just used PowerPoint and Inkscape to draw diagrams. However, when I had to make small modifications to the diagrams and produce numerous diagrams this method quickly became overly time consuming and annoying.
My current project is going to demand even more complex diagrams. I want to find a better method.
Some initial reading has led me to the idea of doing-away with the manual drawing methods and I now think that a command line programming method could be better in the long run. Although there is usually a steep learning curve at the start, which is a bit off-putting. Luckily, I can already use Latex and R so it's not too intimidating and I'll give it a try.
Here is a summary of what I've learned today:
This post from Andrew Wheeler on stack exchange is where I started off and I found it helpful because he describes the exact issues I've been having. The post steered me towards thinking that the Tikz/pgf drawing library in Latex will be the way to go rather than Graphviz. As I saw form another post, Graphviz has trouble drawing curved arrows and also can't handle some of the mathematical notation one might need.
I also rejected the idea of using the in-built visualisation functions from the sem package in R because I'm not planning on using sem to run the analysis in R [I want to use some method for confirmatory path analysis - to be decided if it's going Bayesian or not. For now, I need it to be phylogenetic, so thinking phylogenetic confirmatory path analysis].
Here is a basic diagram. It's only taken me a couple of hours to get to this stage. It's not pretty yet and doesn't have all my variables, but it's an ok start. Mostly, it's adapted from this code by Ivan Griffin.
The document class doesn't actually convert it into a .png. A thread says that this will be possible eventually. But having it like this does at least produce a cropped .pdf document.
Latex code:
\documentclass[convert={density=300,size=1080x800,outext=.png}]{standalone}
\usepackage{tikz} % Load tikz package
\usetikzlibrary{fit,positioning,calc,backgrounds}
\begin{document}
\centering
\begin{tikzpicture} % Encloses drawings in tikz env.
% Styles for states, and state edges
\tikzstyle{state} = [draw, very thick, fill=blue!10, rectangle, minimum height=3em, minimum width=7em, node distance=8em, font={\sffamily\bfseries}]
\tikzstyle{stateEdgePortion} = [black,thick];
\tikzstyle{stateEdge} = [stateEdgePortion,->];
\tikzstyle{edgeLabel} = [pos=0.5, text centered, font={\sffamily\small}];
\tikzstyle{main}=[circle, minimum size = 10mm, thick, draw =red!80, node distance = 16mm]
\tikzstyle{connect}=[-latex, thick]
\tikzstyle{box}=[rectangle, draw=green!100]
% Position the nodes (boxes)
\node[state, name=mrt] {MRT};
\node[state, name=gridcells, below of=mrt, left of=mrt, xshift=-2em] {Grid cells};
\node[state, name=propagule, below of=gridcells] {Propagule length};
\node[state, name=dna, below of=propagule, right of=propagule, xshift=2em] {DNA};
\node[state, name=states, below of=gridcells, right of=gridcells, xshift=20em, node distance=4em] {States};
% Connect the nodes (boxes) via edges (arrows)
\draw ($(propagule.north) + (-.0em,0)$)
edge[stateEdge] node[edgeLabel, xshift=-0em]{\emph{}}
($(gridcells.south) + (-.0em,0)$);
\draw ($(gridcells.north) + (.0em,0)$)
edge[stateEdge, bend left=22.5] node[edgeLabel, xshift=-0em]{\emph{}}
($(mrt.west) + (.0em,0)$);
\draw ($(dna.west) + (-0em,0)$)
edge[stateEdge, bend left=22.5] node[edgeLabel, xshift=-0em, yshift=0em]{}
($(propagule.south) + (0,0em)$);
\draw ($(mrt.east) + (0em,0)$)
edge[stateEdge] node[edgeLabel, xshift=0em, yshift=0em]{\emph{}}
($(states.north) + (0,0em)$);
\end{tikzpicture}
\end{document}
% note - compiled with pdflatex
My current project is going to demand even more complex diagrams. I want to find a better method.
Some initial reading has led me to the idea of doing-away with the manual drawing methods and I now think that a command line programming method could be better in the long run. Although there is usually a steep learning curve at the start, which is a bit off-putting. Luckily, I can already use Latex and R so it's not too intimidating and I'll give it a try.
Here is a summary of what I've learned today:
This post from Andrew Wheeler on stack exchange is where I started off and I found it helpful because he describes the exact issues I've been having. The post steered me towards thinking that the Tikz/pgf drawing library in Latex will be the way to go rather than Graphviz. As I saw form another post, Graphviz has trouble drawing curved arrows and also can't handle some of the mathematical notation one might need.
I also rejected the idea of using the in-built visualisation functions from the sem package in R because I'm not planning on using sem to run the analysis in R [I want to use some method for confirmatory path analysis - to be decided if it's going Bayesian or not. For now, I need it to be phylogenetic, so thinking phylogenetic confirmatory path analysis].
Here is a basic diagram. It's only taken me a couple of hours to get to this stage. It's not pretty yet and doesn't have all my variables, but it's an ok start. Mostly, it's adapted from this code by Ivan Griffin.
The document class doesn't actually convert it into a .png. A thread says that this will be possible eventually. But having it like this does at least produce a cropped .pdf document.
Latex code:
\documentclass[convert={density=300,size=1080x800,outext=.png}]{standalone}
\usepackage{tikz} % Load tikz package
\usetikzlibrary{fit,positioning,calc,backgrounds}
\begin{document}
\centering
\begin{tikzpicture} % Encloses drawings in tikz env.
% Styles for states, and state edges
\tikzstyle{state} = [draw, very thick, fill=blue!10, rectangle, minimum height=3em, minimum width=7em, node distance=8em, font={\sffamily\bfseries}]
\tikzstyle{stateEdgePortion} = [black,thick];
\tikzstyle{stateEdge} = [stateEdgePortion,->];
\tikzstyle{edgeLabel} = [pos=0.5, text centered, font={\sffamily\small}];
\tikzstyle{main}=[circle, minimum size = 10mm, thick, draw =red!80, node distance = 16mm]
\tikzstyle{connect}=[-latex, thick]
\tikzstyle{box}=[rectangle, draw=green!100]
% Position the nodes (boxes)
\node[state, name=mrt] {MRT};
\node[state, name=gridcells, below of=mrt, left of=mrt, xshift=-2em] {Grid cells};
\node[state, name=propagule, below of=gridcells] {Propagule length};
\node[state, name=dna, below of=propagule, right of=propagule, xshift=2em] {DNA};
\node[state, name=states, below of=gridcells, right of=gridcells, xshift=20em, node distance=4em] {States};
% Connect the nodes (boxes) via edges (arrows)
\draw ($(propagule.north) + (-.0em,0)$)
edge[stateEdge] node[edgeLabel, xshift=-0em]{\emph{}}
($(gridcells.south) + (-.0em,0)$);
\draw ($(gridcells.north) + (.0em,0)$)
edge[stateEdge, bend left=22.5] node[edgeLabel, xshift=-0em]{\emph{}}
($(mrt.west) + (.0em,0)$);
\draw ($(dna.west) + (-0em,0)$)
edge[stateEdge, bend left=22.5] node[edgeLabel, xshift=-0em, yshift=0em]{}
($(propagule.south) + (0,0em)$);
\draw ($(mrt.east) + (0em,0)$)
edge[stateEdge] node[edgeLabel, xshift=0em, yshift=0em]{\emph{}}
($(states.north) + (0,0em)$);
\end{tikzpicture}
\end{document}
% note - compiled with pdflatex
No comments:
Post a Comment