# Multiple y axes in groupplot

I want to create a barplot with three groups. Compared are two criteria. To make it more comprehensive here the plot I already generated

I approached this problem by using the example from Stacked barplots/groupplots with text labels in x-coordinate. You can see that criterion 1 has very small values in comparisson to the ones of criterion 2. So the Question is:

How can I create a second y-axis for the values of the second criterion? And how do I scale them?

MWE:

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}

Criterion   criterion1  criterion2
part1       8           2349
part2       8           452
part3       14          1006
}\first

Criterion   criterion1  criterion2
part1       36          10220
part2       36          5891
part3       85          3160
}\second

Criterion   criterion1  criterion2
part1       97          25657
part2       97          18306
part3       184         7461
}\third

\begin{document}

\begin{tikzpicture}
\begin{groupplot}
[group style={%
columns=3,
group name=plots,
xlabels at=edge bottom,
y descriptions at=edge left,
},
ybar,
ymin=0,
ymax=27e3,
enlarge x limits={abs=.5},
width=0.45\textwidth,
height=0.6\textwidth,
scaled y ticks=base 10:-3,
xticklabels from table={\first}{Criterion},
x tick label style={rotate=90,anchor=east},
xtick=data,
]

\nextgroupplot[xlabel=item1,legend to name=grouplegend,ylabel=y-label]
\pgfplotstableforeachcolumn\first\as\col{%
\ifnum\pgfplotstablecol=0
\else
\edef\tmp{%
}%
\tmp
\fi
}

\nextgroupplot[xlabel=item2]
\pgfplotstableforeachcolumn\second\as\col{%
\ifnum\pgfplotstablecol=0
\else
\edef\tmp{%
}%
\tmp
\fi
}

\nextgroupplot[xlabel=item3]
\pgfplotstableforeachcolumn\third\as\col{%
\ifnum\pgfplotstablecol=0
\else
\edef\tmp{%
}%
\tmp
\fi
}
\end{groupplot}

\node at (plots c2r1.north) [anchor=south, yshift=.6cm] {\ref{grouplegend}};
\end{tikzpicture}

\end{document}

-
My answer in that question should still suffice. You just need to scour the manual for how to make the plots look like you want. For instance how not to display the axis on the right hand side, how to add a second y-axis etc. How to fix the y-min/max. –  zeroth Dec 20 '11 at 13:30
This is very similar to the question Different scales on the same plot. See if you can adapt that approach (which is taken directly from the manual, like zeroth suggested) to your situation. If you run into trouble, feel free to edit your question to make it more specific. –  Jake Dec 20 '11 at 22:31
Sorry but I just don't get it. for the axis environment it is quite easy but how does it work in the groupplot? –  Lorzen Dec 21 '11 at 13:14
Admittedy a non-answer (hence the comment), but why not use GNUPlot? There's a great reference-ish page here ;) –  mpr Dec 21 '11 at 16:02
@Lorzen: When there's more than one other person commenting on a question, you have to include @<name> to notify a user of your comment. –  Jake Dec 22 '11 at 7:52

The approach for combining different y-axes when using groupplots is very similar to that when using just one plot: You draw the second set of plots on top of the first one, hiding the axis lines and axis labels, and moving the y(tick)labels to the other side:

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.4}

Criterion   Wasserverbrauch   {CO$_2$-Emission}
Komp        8           2349
Komp+PV 8           452
Sorp        14          1006
}\Rapperswil

Criterion   Wasserverbrauch   {CO$_2$-Emission}
Komp        36          10220
Komp+PV 36          5891
Sorp        85          3160
}\Palermo

Criterion   Wasserverbrauch   {CO$_2$-Emission}
Komp        97          25657
Komp+PV 97          18306
Sorp        184         7461
}\Jeddah

\begin{document}

\begin{tikzpicture}
\pgfplotsset{
water/.style={
fill=cyan,
draw=cyan!50!black
},
co2/.style={
fill=orange,
draw=orange!50!black
}
}

\begin{groupplot}[
group style={
columns=3,
group name=plots,
x descriptions at=edge bottom,
y descriptions at=edge left,
},
ylabel={[ML]}, ylabel style=cyan!50!black,
yticklabel style=cyan!50!black,
ybar, /pgf/bar shift=-6pt, % We have to manually move the bars
ymin=0, ymax=270,
enlarge x limits={abs=.5},
width=0.4\textwidth,
height=0.6\textwidth,
xticklabels from table={\Rapperswil}{Criterion},
x tick label style={rotate=90,anchor=east},
xtick=data, xtick pos=left,
legend columns=2]

\nextgroupplot[xlabel=Rapperswil,legend to name=grouplegend]
\addplot [water] table [x expr=\coordindex,y index=1] {\Rapperswil};
\addlegendentry{CO$_2$-Emission}

\nextgroupplot[xlabel=Palermo]
\addplot [water] table [x expr=\coordindex,y index=1] {\Palermo};

\nextgroupplot[xlabel=Jeddah]
\addplot [water] table [x expr=\coordindex,y index=1] {\Jeddah};
\end{groupplot}

\begin{groupplot}
[group style= {
columns=3,
group name=plots,
y descriptions at=edge right,
},
ybar, /pgf/bar shift=6pt,
ymin=0, ymax=2.7e4,
enlarge x limits={abs=.5},
width=0.4\textwidth,
height=0.6\textwidth,
xtick=\empty, axis line style=transparent,
ylabel={[kg CO$_2$ per year]},yticklabel style=orange!75!black,
ylabel style=orange!75!black]

\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2] {\Rapperswil};

\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2,
] {\Palermo};

\nextgroupplot
\addplot [co2] table [x expr=\coordindex,y index=2] {\Jeddah};
\end{groupplot}

\node at (plots c2r1.north) [anchor=south, yshift=.6cm] {\ref{grouplegend}};
\end{tikzpicture}

\end{document}

-