4

How to draw such a diagram in Tikz in the easiest way?

You can send a link to a similar example.

MWE:

\documentclass[tikz, border=2pt]{standalone}
\usepackage[main=russian,english]{babel}
\usepackage[tracking=true]{microtype}
%==========================================================
\microtypecontext{kerning=russian}
\babelfont{rm}[Scale=0.976]{Times New Roman}
%\babelfont{tt}[Scale=0.976]{Courier New}
\linespread{0.976}
%==========================================================
\usepackage{pgfplots}
%==========================================================
\begin{document}
\noindent\begin{tikzpicture}

\begin{axis}[
    ybar,
    grid=both,
    bar width=24pt,
    bar shift=0pt,  %% <-- added
    ylabel near ticks,      
    yticklabel pos=right,
    symbolic x coords={RETRIEVAL ACCURACY, USAGE, INITIAL LEARNING, SUPERVISOR QUESTIONS, ERROR RATES, READING TIME, NUMBER OF WORDS},
    ytick={-100,0,100}, %% <-- added
    ]
    \addplot[fill=blue] coordinates {
        (RETRIEVAL ACCURACY, 32)
        (USAGE, 38)
        (INITIAL LEARNING, 83)
    };
    
    \addplot[fill=red] coordinates {
        (SUPERVISOR QUESTIONS, -90)
        (ERROR RATES, -54)
        (READING TIME, -50)
        (NUMBER OF WORDS, -30)
    };
\end{axis}
\end{tikzpicture}
\end{document}

What I get:

enter image description here

What I want to receive:

Source: https://informationmapping.com/pages/information-mapping-methodology:

enter image description here

3
  • 1
    Do you have some code? Have you read the tutorials at the start of the manual? Searched for similar diagrams? Right now, this is just a do-it-for-me and likely to get closed. If you can show what you've tried, people will be happy to help. Or there are people you can hire to prepare diagrams for you - just this is not the place to do that. You are not new to PGF/TikZ and have asked questions about it before, including MWEs in at least some cases. In doubt, see tex.meta.stackexchange.com/q/228.
    – cfr
    Commented May 20 at 16:19
  • I don't think my example will help, @ago.
    – Youra_P
    Commented May 20 at 16:37
  • Are you using Russian? The image you show isn't in Russian. What data are you working with? If your example is from somebody else, don't forget to include a link.
    – cfr
    Commented May 20 at 16:40

2 Answers 2

8

Here is a macro that creates the graph.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary {decorations.markings}

\tikzset{
    pctnode/.style={decoration={markings, mark=at position -3mm with{\node[white]{$#1\%$};}}, postaction=decorate},
    sgnpos1/.style={below=-6mm},
    sgnpos-1/.style={above=-6mm},
    sgncol1/.style=blue,
    sgncol-1/.style=red
}

\newcommand{\horscale}{1.7}
\newcommand{\verscale}{.7}
\newcommand{\mygraph}[2][]{
    \begin{tikzpicture}
        \foreach \p/\l[count=\n, evaluate=\p as \lbl using sign(\p)] in {#2}{
            \draw[line width=\horscale*9mm, sgncol\lbl, pctnode=\p] (\horscale*\n,\p/10*\verscale)--(\horscale*\n,0)
                node[align=center, sgncol\lbl, font=\tiny, sgnpos\lbl, inner ysep=0pt]{\l};
        }
    \end{tikzpicture}
}

\begin{document}

\mygraph{+32/RETRIEVAL\\ACCURACY, +38/USAGE, +83/INITIAL\\LEARNING, +90/SUPERVISOR\\QUESTIONS, -54/ERROR\\RATES, -50/READING\\TIME, -30/NUMBER OF\\WORDS}

\end{document}
0
4

Here is one way to do it, resulting from expanding the simplest approach while continuously refactoring said code.

pgfplots is perfect to display scientific data. Your graphic doesn't match that format. Though you can do some of the things below with the nodes also in pgfplots, it gets more complicated when it comes to the coordinates in the drawn window.

So I suggest to take the route a graphic designer might take:

  • draw a series of thick vertical colored lines (which we interprete as bars)
  • put some text (values and labels)

So the key action inside a tikzpicture environment will be placing bars like:

    % ~~~ variant 1: manual placement ~~~~~~~~~
    \barp{-2}{+32}{RETRIEVAL\\\textbf{ACCURACY}}
    \barp{-1}{+38}{USAGE}
    \barp{ 0}{+83}{\textbf{INITIAL}\\LEARNING}

    \barn{1}{-90}{\textbf{SUPERVISOR}\\QUESTIONS}
    \barn{2}{-54}{ERROR\\\textbf{RATES}}
  • barp takes care of positive bars, barn ... you guess it
  • first parameter is an integer coordinate: idea is to just count the positions
  • where you start doesn't matter, as long as the intervals are integer
  • scaling is done inside \bar. (interacting with \xf, the font tweakings AND yshifts)
  • second parameter is the value
  • third is regular text, broken by \\
  • HINT: use short texts, even shorter than your example shows

You can also use \foreach-loops, here shown for \barn, passing the 3 parameters:

    % ~~~ variant 2: loop ~~~~~~~~~~~~~~~~~
    \foreach \n/\val/\t in {3/-50/READING\\\textbf{TIME},
                            4/-30/\textbf{NUMBER OF}\\WORDS}
        \barn{\n}{\val}{\t};

The bar-macros are a generalization of the actions I described in the beginning, taking \yf scaling into account, to create a single bar, like:

    \draw[barp] (0,0)        %  starting point to draw a (thick) line
        node[valp] {+32\%}   %  value-related text at (0,0)
        node[txtp] {some\\**text**}%    label related text
         -- +(0,2);          % make a relative move of 2cm up

The styles are made hieracrchically by intention, i.e. to make relevant changes in one place only, like:

    bar/.style={line width=11mm},
       barp/.style={bar, draw=\colp}, % reuse line width, i.e. bar
       barn/.style={bar, draw=\coln}, % same, with a different color

\xline is a simple \draw, which accounts for scaling of x via \xf. Note that you can pass the colore.


Adjustments I would restrict to:

  • \yf (scaling of y-axis)
  • \colp and \coln (changing colors)

Of course you could create some space around the \xline inside the \bar. macros.

As a process I would:

  • create those drawings with the standalone class, as shown
  • include the compiled .pdf via \includegraphics from package graphicx

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{calc}

% ~~~ colors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand\colp[0]{brown!50!purple!70}
\newcommand\coln[0]{brown!50!purple!90}

% ~~~ scalings ~~~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand\xf[0]{1.2}
\newcommand\yf[0]{0.02}

% ~~~ bars ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% #1: integer position
% #2: value
% #2: label
\newcommand\barp[3]{%
    \draw[barp] ($\xf*(#1,0)$)% starting point to draw a (thick) line
        node[valp] {#2\%}%      value-related text
        node[txtp] {#3}%        label realted text
         -- +($\yf*(0,#2)$);}%  y-coordinate, i.e. length of (thick) line
         
\newcommand\barn[3]{%           same for negative bars
    \draw[barn] ($\xf*(#1,0)$)%
        node[valn] {#2\%}%
        node[txtn] {#3}%
         -- +($\yf*(0,#2)$);}

% ~~~ horizontal line ~~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand\xline[3]{\draw[#1] ($\xf*(#2,0)$) -- ($\xf*(#3,0)$);}


% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
 \begin{tikzpicture}[% ~~~ styles ~~~~~~~~~~~~~~~~
    bar/.style={line width=11mm},
    barp/.style={bar, draw=\colp}, 
    barn/.style={bar, draw=\coln}, 
    %
    val/.style={font={\sf\small},text=white},
    valp/.style={val,yshift=3mm},
    valn/.style={val,yshift=-3mm},
    %
    txt/.style={font={\sf\tiny},align=center},
    txtp/.style={txt,text=\colp,anchor=north,yshift=5mm},
    txtn/.style={txt,text=\coln,anchor=south,yshift=-5mm},
 ]% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    % ~~~ variant 1: manual placement ~~~~~~~~~
    \barp{-2}{+32}{RETRIEVAL\\\textbf{ACCURACY}}
    \barp{-1}{+38}{USAGE}
    \barp{ 0}{+83}{\textbf{INITIAL}\\LEARNING}

    \barn{1}{-90}{\textbf{SUPERVISOR}\\QUESTIONS}
    \barn{2}{-54}{ERROR\\\textbf{RATES}}

    % ~~~ variant 2: loop ~~~~~~~~~~~~~~~~~
    \foreach \n/\val/\t in {3/-50/READING\\\textbf{TIME},
                            4/-30/\textbf{NUMBER OF}\\WORDS}
        \barn{\n}{\val}{\t};
    
    % ~~~ horizontal line ~~~~~~~~~~~~~~~~~~
    \xline{black!30}{-3}{5}          
 \end{tikzpicture}
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .