I have earlier asked two questions here related to barplots and labels/ticks for double y-axes: (1) How to make an xbar plot, with pgfplots, having different y tick labels on the left and right side y axis?, and (2) How to order barplots in aligned rows and columns?, and got good answers.
In my former question number (2) I needed to order barplots in 3 rows and 2 colums. In each row the leftmost barplot had outer yticks and ytick labeles on its left side, while the rightmost barplot had yticks and ytick labels on its right side. In addition, the ylabel for each barplot was turned horizontally and placed above the ytick labels.
My new question here is a combination of my previous two : How can I reduce the number of barplot columns, in question (2), from two to one, but retain all other structure, i.e. the single barplot in each row should have outer yticks, ytick labels and ylabel on both its left and right side?
Although the answer I got to my original two questions are very good ones, I am, unfortunalely, not able to combine them to answer my new question.
Below I have added the code I got from StackExchange as an answer to my previous question (2).
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{
compat=newest,
width=4cm,
height=4cm,
title style = {yshift = 10pt,name=title},
xtick align = inside,
xtick pos = both,
xticklabel pos = upper,
yticklabel style={name=yticklabel},
xlabel style={name=xlabel},
ylabel style={rotate=-90},
xmin=-5,
xmax = 140,
ytick align = outside,
ytick pos = left,
yticklabel pos=left,
ymin =0,
ymax = 5,
ytick=data,
xbar,
nodes near coords,
every node near coord/.append style = {anchor=west},
yticklabel shift=0.25cm,
region/.style={
extra description/.append code={\node (region label) at ({yticklabel cs:0.5}-|ylabel.west) [anchor=east,xshift=-1ex] {#1};}
},
region title/.style={
extra description/.append code={\node at (region label.east|-xlabel.base) [anchor=base east] {#1};}
}
}
% Measurements contry 1
\begin{filecontents}{data1.dat}
Age-interval Y-Position meas1 meas2 winner
20-30 1 15 45 John
30-40 2 20 13 Al
40-50 3 12 4 Andrew
50-60 4 24 1 Tom
\end{filecontents}
% Measurements contry 2
\begin{filecontents}{data2.dat}
Age-interval Y-Position meas1 meas2 winner
20-30 1 44 30 Peter
30-40 2 15 33 Steve
40-50 3 2 48 David
50-60 4 66 98 Alister
\end{filecontents}
% Measurements contry 3
\begin{filecontents}{data3.dat}
Age-interval Y-Position meas1 meas2 winner
20-30 1 13 22 Arne
30-40 2 1 48 Per
40-50 3 2 4 Ola
50-60 4 33 61 Anders
\end{filecontents}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}
\begin{tikzpicture}
\matrix[column sep=4pt, row sep=2pt]{
\begin{axis}[
xlabel = {Meas. 1},
yticklabel pos=left,
yticklabels from table={data1.dat}{Age-interval},
ylabel = {Age interval},
ylabel style = {
at=(yticklabel.east|-xlabel.base),
anchor=base east,
name=ylabel
},
bar width=4pt,
region=Ohio,
region title=Region
]
\addplot table [
y=Y-Position,
x=meas1,
] {data1.dat};
\end{axis}
&
\begin{axis}[
xlabel = {Meas. 2},
yticklabel pos=right,
yticklabels from table={data1.dat}{winner},
ylabel = {Winner},
ylabel style = {
at={(yticklabel.west|-xlabel.base)},
anchor=base west,
},
ytick pos = right,
bar width=4pt,
]
\addplot table [
y=Y-Position,
x=meas2,
] {data1.dat};
\end{axis}
\\
\begin{axis}[
yticklabel pos=left,
yticklabels from table={data2.dat}{Age-interval},
bar width=4pt,
xticklabels = none,
region=South Carolina
]
\addplot table [
y=Y-Position,
x=meas1,
] {data2.dat};
\end{axis}
&
\begin{axis}[
yticklabel pos=right,
yticklabels from table={data2.dat}{winner},
ytick pos = right,
bar width=4pt,
xticklabels = none,
]
\addplot table [
y=Y-Position,
x=meas2,
] {data2.dat};
\end{axis}
\\
\begin{axis}[
yticklabel pos=left,
yticklabels from table={data3.dat}{Age-interval},
bar width=4pt,
xticklabels = none,
region=Norway
]
\addplot table [
y=Y-Position,
x=meas1,
] {data3.dat};
\end{axis}
&
\begin{axis}[
yticklabel pos=right,
yticklabels from table={data3.dat}{winner},
ytick pos = right,
bar width=4pt,
xticklabels = none,
]
\addplot table [
y=Y-Position,
x=meas2,
] {data3.dat};
\end{axis}
\\};
\end{tikzpicture}
\caption{Results of some contest for men}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
This code produces the following figure:
So posing my new question in a new way: how to delete the second column of barplots, that one below and including the "Meas. 2" heading, in the figure above and keeping the columns "Region", "Age interval", "Meas. 1" and "Winner", as well as equipping the barplots under "Meas. 1" with outer yticks also on its right side?
Thanks Jake. That answer helped me a lot! Here you have your bounty points :) Though...I have two follow-up questions. I am not sure if this is the right place, but I think these questions are very related to the example I use above:
1) How can I left/center/right justify the words in each of the colums "Region", "Age interval", and "Winner"?
2) If I want to add another column with additional information about each winner, say his or her body weigth, how can I add that? I guess in case that the y-tick options are used up since I have used them on both left and right side of the bar plots?