0

I have the following code which roughly approximates a diagram I want to make with tikz:

\begin{tikzpicture}
\begin{axis}[
% (normal text should not be set in math mode)
xlabel=,
ylabel=,
% if you use `data' ticks will be set on every x coordinate that is
% given by the *first* `\addplot' command
xtick=data,
xticklabels={
    Control,
    Voucher,
    Transfer%
},
ytick=data,
yticklabels={
    No increase,
    Increase%
},
% use the following key so the baseline of all ticklabel entries is the same
% (compare this image to the one from marmot)
typeset ticklabels with strut,
% there is one default value for the `legend pos' that is outside the axis
legend pos=outer north east,
% (so the legend looks a bit better)
legend cell align=left,
% (moved this common key here),
]
% (renamed `plot coordinates' by `coordinates'
\addplot [mark=*,blue] coordinates {
    (1,1)
    (2,1)
    (3,1)
};

\addplot [color=red,mark=x] coordinates {
    (1,1)
    (2,1)
    (3,2)
};

\addplot [color=green,mark=x] coordinates {
    (1,1)
    (2,2)
    (3,2)
};

% (replaced `\addlegendentry's with `\legend')
\legend{
    Pure Altruism,
    Warm Glow,
    Mental Accounting,
}
\end{axis}
\end{tikzpicture}

enter image description here

As you can see, I have attempted to add y axis tick labels, but this has not emerged in the actual diagram itself. Further, what I am trying to illustrate is discrete in nature, so I want there to be three adjacent bars for each tick on the x axis that will illustrate whether the level should be 'high' or 'low' under each of the theories in the legend.

How can I convert this to a bar chart with three adjacent bars and add the two y axis labels I need?

pchaigno
  • 11,313
  • 2
  • 29
  • 54
spar31415
  • 21
  • 1
  • 5

1 Answers1

2

As per this answer, when you use ytick=data, the labels are extracted from the first \addplot command used. Your first \addplot command only contains 1 as y tick label.

You can either explicitly define the labels:

ytick={1, 2},

or change the order of your \addplot commands to have a more representative one first (one with both all x tick labels and all y tick labels).

enter image description here

pchaigno
  • 11,313
  • 2
  • 29
  • 54