What I want to plot
I'd like to plot several stacked xbar plots where each bar plot contains two values. The total from each xbar-plot is based on one unit, i.e. the smallest bar represents "1" while the other are a multiple from this plot, e.g. 2 or 2.5 etc.
The two values per stacked plot are then percentages, i.e. 80% and 20%.
The problem
On the X axis I want the scale from 0 to the max value with one axis for all plots. On each stacked plot I want to plot a scale ranging from 0% to 100%. The problem is: I can either plot only the absolute value on the X-axis or have the percentages per bar plot but not a mixture.
I want to know if there is a way to set something like a local coordinate system for each bar-plot. Or any hint to set the min and max value for the scale of a bar-plot. Or, a way hoe I can multiply the ticks from the percentages by the scaling factor.
My code so far:
%% my preamble
\documentclass[11pt, a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,
calc,
matrix,
positioning,
pgfplots.dateplot,
shapes.geometric,
shapes.misc,
shapes.arrows,
shapes.symbols
}
\begin{tikzpicture}
\pgfplotsset{
every linear axis/.append style =
{
width = 3cm,
font = \scriptsize,
%scale only axis %% uncommenting this results scales percentage over
%% absolute value: not desired
},
stacked/.style =
{
xbar stacked,
bar width = 5pt,
axis y line = none,
xmin = 0,
xmax = 40, %% largest value, needed to set absolute max
scale only axis %% commenting this results in too short percentage
%% scales
},
percent/.style =
{
xmin = 1,
ymin = 0,
ymax = 1,
axis y line = none,
axis x line* = top,
yshift = 0.5cm,
}
}
\begin{scope}[yshift = 4.75cm, xshift = 7cm]
\begin{axis}[stacked, axis x line = none]
\addplot coordinates { (14.45, 0) };
\addplot coordinates { ( 2.55, 0) };
\end{axis}
\begin{axis}
[percent, xmax = 17,
x coord trafo/.code= %% routine to transform absolute values into
%% percentages
{
\pgfmathparse{#1 / 17 * 100}
}]
\end{axis}
\end{scope}
%% almost the same as above. However, using the last entry to plot
%% absolute X-axis
\begin{scope}[yshift = 2.5cm, xshift = 7cm]
\begin{axis}[stacked, xmax = 40, axis x line* = bottom]
\addplot coordinates{ (32, 0) };
\addplot coordinates{ ( 8, 0) };
\end{axis}
\begin{axis}[percent, xmax = 40,
x coord trafo/.code=
{
\pgfmathparse{#1 / 40 * 100}
}]
\end{axis}
\end{scope}

