Reputation: 393
I am interested in displaying a causal mechanism visually with some plain boxes/circles connected by arrows in my paper written in RMarkdown. Something like this:
How is this done in RMarkdown? Would you recommend me to create a picture in a another app and import to RMarkdown like a picture?
Upvotes: 3
Views: 2368
Reputation: 44867
I think the best way to do this is to use Tikz to draw the graphics. There's an example at https://github.com/yihui/knitr-examples/blob/master/058-engine-tikz.Rmd, where the code chunk includes
```{tikz, tikz-ex, fig.cap = "Funky tikz", fig.ext = 'png', cache=TRUE}
\usetikzlibrary{arrows}
\begin{tikzpicture}[node distance=2cm, auto,>=latex', thick, scale = 0.5]
\node (P) {$P$};
\node (B) [right of=P] {$B$};
\node (A) [below of=P] {$A$};
\node (C) [below of=B] {$C$};
\node (P1) [node distance=1.4cm, left of=P, above of=P] {$\hat{P}$};
\draw[->] (P) to node {$f$} (B);
\draw[->] (P) to node [swap] {$g$} (A);
\draw[->] (A) to node [swap] {$f$} (C);
\draw[->] (B) to node {$g$} (C);
\draw[->, bend right] (P1) to node [swap] {$\hat{g}$} (A);
\draw[->, bend left] (P1) to node {$\hat{f}$} (B);
\draw[->, dashed] (P1) to node {$k$} (P);
\end{tikzpicture}
```
and the output (in HTML or PDF format; this is from PDF) looks like this:
Upvotes: 2