Graphics, Figures & TablesCausal Diagram and Forest Trees Question

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagram and Forest Trees Question

Post by asmithb »

Dear Sir or Madam,

I want to create a causal diagram (forest tree), in which the causal chain looks like this:

Increase in Oil Wealth >> Increase in Public Expenditures >> Increase in Patronage and Corruption

Then, from Increase in Patronage and Corruption, 2 causal arrows with 2 sons are derived:

Increase of Electoral Support of The Executive and Increase of Ruling Coalition Support. From these 2, a common and final child is derived: Decrease in Executive Constraints.

So far, I have the following code:

Code: Select all


\documentclass{article}
\usepackage{tikz,amsmath,amssymb,stmaryrd}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}

\usetikzlibrary{arrows,shapes,positioning,shadows,trees}


\begin{document}






\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 4/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 5/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
                   
}


\begin{tikzpicture}[
  level 1/.style={sibling distance=40mm},
  edge from parent/.style={->,draw},
  >=latex]

% root of the the initial tree, level 1
\node[root] {$\uparrow$ Oil Wealth}
% The first level, as children of the initial tree
  child {node[level 2] (c1) {$\uparrow$ Public Expenditures}}

  child {node[level 3] (c1) {$\uparrow$ Patronage and Corruption}}
  
  
 
  child {node[level 4] (c1) {$\uparrow$ Electoral Support of the Executive}}
  
  child {node[level 4] (c2) {$\uparrow$ Ruling Coalition Support of the Executive}}

  
  child {node[level 5] (c1) {$\downarrow$ Weakening of Executive Constraints}}


\end{tikzpicture}

\end{document}


Thank you
Last edited by asmithb on Mon Mar 29, 2021 5:11 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Causal Diagram and Forest Trees Question

Post by Ijon Tichy »

Please try the (automatically added) button "Run LaTeX here" below your code. As you can see, your code snippet is not enough to make it running without error. So please extend it into a Infominimal working example.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagram and Forest Trees Question

Post by asmithb »

Code: Select all

\documentclass{article}
\usepackage{tikz,amsmath,amssymb,stmaryrd}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}

\usetikzlibrary{arrows,shapes,positioning,shadows,trees}


\begin{document}






\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 4/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 5/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
                   
}


\begin{tikzpicture}[
  level 1/.style={sibling distance=40mm},
  edge from parent/.style={->,draw},
  >=latex]

% root of the the initial tree, level 1
\node[root] {$\uparrow$ Oil Wealth}
% The first level, as children of the initial tree
  child {node[level 2] (c1) {$\uparrow$ Public Expenditures}}

  child {node[level 3] (c1) {$\uparrow$ Patronage and Corruption}}
  
  
 
  child {node[level 4] (c1) {$\uparrow$ Electoral Support of the Executive}}
  
  child {node[level 4] (c2) {$\uparrow$ Ruling Coalition Support of the Executive}}

  
  child {node[level 5] (c1) {$\downarrow$ Weakening of Executive Constraints}}


\end{tikzpicture}

\end{document}



Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Causal Diagram and Forest Trees Question

Post by Bartman »

The example is unfortunately still not executable.

What prevents the execution?
  • The empty line after the last style in the argument of the \tikzset command
  • The missing semicolon at the end of the tree
  • Every node should be given a unique name if you want to choose it yourself.
One way to achieve what you want would be as follows:

Code: Select all

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,shadows,positioning}

\begin{document}
\tikzset{
  basic/.style={
    draw, 
    text width=2cm, 
    drop shadow, 
    font=\sffamily
  },
  root/.style={
    basic, 
    rounded corners=2pt, 
    thin, 
    align=center,
    fill=green!30
  },
  child node/.style={
    basic, 
    rounded corners=6pt, 
    thin,
    align=center, 
    fill=green!60,
    text width=8em,
    anchor=north
  },
  every child node/.style={child node}
}

\begin{tikzpicture}[
  sibling distance=4cm,
  edge from parent/.append style={->},
  >=Latex
]

% root of the the initial tree, level 1
\node [root] (root) {$\uparrow$ Oil Wealth}
  % The first level, as children of the initial tree
  child {node {$\uparrow$ Public Expenditures}
    child {node {$\uparrow$ Patronage and Corruption}
      child {node {$\uparrow$ Electoral Support of the Executive}}
      child {node {$\uparrow$ Ruling Coalition Support of the Executive}}
    }
  }
;
\path (root-1-1-1.south) -- coordinate (midway)  (root-1-1-2.south);
\node [below=of midway, child node] (wec) 
  {$\downarrow$ Weakening of Executive Constraints}
;
\path [->]
  (root-1-1-1) edge (wec)
  (root-1-1-2) edge (wec)
;
\end{tikzpicture}
\end{document}
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagram and Forest Trees Question

Post by asmithb »

Thank you very much!
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagram and Forest Trees Question

Post by asmithb »

I have another question related to this diagram. How could I increase the length of the arrows? Look at how the black arrows are too short, especially between the second and the third boxes.

Code: Select all

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,subcaption, hyperref, color,setspace,sectsty,comment,footmisc,caption,natbib,pdflscape,subfigure,array, enumerate, natbib, indentfirst, float, tikz, rotating, lipsum, adjustbox, booktabs, multirow, soul, changepage,threeparttable}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}



\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}  

\hypersetup{colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=black, plainpages=false, pdfpagelabels=true, urlcolor=blue}


\usepackage[nameinlink, capitalise, noabbrev]{cleveref}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands

\normalem

\onehalfspacing
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}{Proposition}
\newtheorem{conj}{Conjecture}

\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}

\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand{\thesubhyp}{\thehyp\alph{subhyp}}

\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}

\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}


\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\newcommand{\FixedLengthArrow}{2,0}

\begin{document}
\tikzset{
  basic/.style={
    draw,
    text width=3cm, 
    drop shadow, 
    font=\sffamily
  },
  root/.style={
    basic, 
    rounded corners=2pt, 
    thin, 
    align=center,
    fill=green!30
  },
  child node/.style={
    basic, 
    rounded corners=6pt, 
    thin,
    align=center, 
    fill=green!60,
    text width=10em,
    anchor=north
  },
  every child node/.style={child node}
}

\begin{figure}[H]
\centering
\begin{tikzpicture}[
  sibling distance=6cm,
  edge from parent/.append style={->},
  >=Latex
]

% root of the the initial tree, level 1
\node [root] (root) {Oil Wealth}
  % The first level, as children of the initial tree
  child {node {No access (no state ownership and no control)}
  child {node {Low Societal Expectations, High Transaction Costs, Small-Sized  Winset}
    child {node {Strong Fiscal Regime}
         child {node {Greatest Transparency and Budget Stability} 
        child {node  {Strong Executive Constraints}}
  }}}}
  child {node {Partial Access}
    child {node {High Societal Expectations, High Transaction Costs, Medium-Sized Winset}
    child {node {Hybrid Fiscal Regime}
         child {node {Mid-Level Transparency and Budget Stability}
        child {node  {Moderate Executive Constraints}}
  }}}}
    child {node {Full Access}
    child {node {High Societal Expectations, Low Transaction Costs, Large-Sized Winset}
    child {node {Weak Fiscal Regime}
         child {node {Lowest Transparency and Budget Stability}
        child {node  {Weak Executive Constraints}}
  }}}}
;
\path (root-1-1-1.south)  -- coordinate (midway)   (root-1-1-1.south) ;


  
;
\end{tikzpicture}
\caption{Causal Mechanisms of Oil Wealth in Civilian Dictatorships} 
\label{fig: Causal}
\end{figure}  

\end{document}


Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Causal Diagram and Forest Trees Question

Post by Bartman »

That looks like a new topic. You can refer to an old one with a link in the new topic if you want to.

Please remove the sources of error in your example and try to limit it to the required source code.

Load either subcaption or subfigure, the former being preferable to the obsolete latter.

Loading hyperref first without and then again with options generates an option clash error.

You could e.g. adjust the distances between the boxes by adding the growth parent anchor=south option to the tikzpicture environment.

Deal with level distance, if you want to have smaller distances.
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Causal Diagram and Forest Trees Question

Post by asmithb »

Thank you. I have another question.

How do I make the arrows have a different length from each other? I see that both growth parent anchor=south and level distance make all the arrows have the same length.

How do I add text next to each arrow to describe how the causal mechanism works. For instance, take a look at the Strong Fiscal Regime Box. I imagine I want to add the word "Generate" next to the arrow on the left side, meaning that transparency and budget stability generate strong executive constraints. How could I do it?

How do I change the style of the arrows? If I want a much thicker arrow, for example. Or an arrow that looks more or less like a rectangle on top of a triangle (a very thick arrow that looks like a figure instead)?

Finally, how could I change the color of the last row boxes? The ones that contain the word "Executive Constraints"?
Post Reply