I need help with a few adjustments on this group plot. I managed to solved my previous problem but now I´m searching for a needle in a haystack.
1. How do I make the bars thinner so they may fit better?
- I have tried to adjust (ybar= 0-10pt) + (2*\pfglinewidth) on BOTH
- I have tweaked between all the variables I can find back and forth… some don´t seem to make any differences (ybar).
2. How do I adjust the width of the individual boxes?
- They need to have same width of course but haven't found anything that seems to change it. Adjusting general width just makes the whole "image" more distorted. I want to better fit the bars of course.
3. How do I add error bars with these code settings?
- I have recently used error bars like below with success. However, can I pass the same argument since my inline table is located in different locate within code?
\addplot [draw=green,fill=green!25,error bars/.cd, y dir=both, y explicit] coordinates {
Table with data
x y z
}
Blockquote
Code is now fully compilable.
\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\usepackage{changepage}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=1.12}
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 8 2349
Komp+PV 8 452
Sorp 14 1006
ABC 230 1006
}\Rambo
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 100 10220
Komp+PV 36 5891
Sorp 85 3160
ABC 45 3400
}\Godfather
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\Jedi
\pgfplotstableread{
Criterion Wasserverbrauch {CO$_2$-Emission}
Komp 230 25657
Komp+PV 97 18306
Sorp 184 7461
ABC 240 7461
}\LordVader
\begin{document}
\begin{adjustwidth}{-13em}{1em}
\begin{tikzpicture}
\pgfplotsset{
water/.style={
fill=cyan,
draw=cyan!50!black
},
co2/.style={
fill=orange,
draw=orange!50!black
}
}
\begin{groupplot}[
group style={
columns=4,
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 = 0pt, /pgf/bar shift=-12pt, % We have to manually move the bars
ymin=0, ymax=270,
enlarge x limits={abs=.5},
width=0.45\textwidth,
height=0.6\textwidth,
xticklabels from table={\Rambo}{Criterion},
x tick label style={rotate=90,anchor=east},
xtick=data, xtick pos=left,
legend columns=2]
\nextgroupplot[xlabel=Rambo,legend to name=grouplegend]
\addplot [water] table [x expr=\coordindex,y index=1] {\Rambo};
\addlegendentry {Wasserverbrauch}%
\addlegendimage{co2,ybar legend}
\addlegendentry{CO$_2$-Emission}
\nextgroupplot[xlabel=Godfather]
\addplot [water] table [x expr=\coordindex,y index=1] {\Godfather};
\nextgroupplot[xlabel=Jedi]
\addplot [water] table [x expr=\coordindex,y index=1] {\Jedi};
\nextgroupplot[xlabel=LordVader]
\addplot [water] table [x expr=\coordindex,y index=1] {\LordVader};
\end{groupplot}
\begin{groupplot}
[group style= {
columns=4,
group name=plots,
y descriptions at=edge right,
},
ybar = 0pt, /pgf/bar shift=0pt,
ymin=0, ymax=2.7e4,
enlarge x limits={abs=.5},
width=0.45\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] {\Rambo};
\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2,
] {\Godfather};
\nextgroupplot[scaled y ticks=false]
\addplot [co2] table [x expr=\coordindex,y index=2,
] {\LordVader};
\nextgroupplot
\addplot [co2] table [x expr=\coordindex,y index=2] {\Jedi};
\end{groupplot}
\node at (plots c2r1.north) [anchor=south, yshift=.6cm] {\ref{grouplegend}};
\end{tikzpicture}
\end{adjustwidth}
\end{document}
Best Answer
Since you didn't provide any data for the error bars -- but you already found a solution yourself anyway -- here is a solution for the remaining 2 problems 1 and two.
For more details please have a look at the comments in the code.