If you use ybar
in the axis options, each plot series will get a different amount of bar shift
to keep the bars from overlapping. Usually, that's exactly what you want. However, in your case, you'll want to set bar shift=0pt
in the axis options:
\documentclass{memoir}
\usepackage[left=1.5in, right=1in, top=1in, bottom=1in, headsep=0.1in, head=0.4in, includehead, includefoot, marginparsep=0in, marginparwidth=0in,footskip=0.4in]{geometry}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{xcolor}
\pagecolor{black}
\pgfplotsset{width=7cm,compat=1.5.1}
\usepackage{siunitx}
\sisetup{inter-unit-product={}\cdot{},sticky-per=true,multi-part-units=single,separate-uncertainty=true,list-units=single,range-units=single,detect-all,detect-weight=true,detect-inline-weight=math}
\DeclareSIUnit\calorie{cal}
\DeclareSIUnit\kcal{\kilo\calorie}
\DeclareSIUnit\kcalpmole{kcal\per\mole}
\definecolor{hoyemagenta}{HTML}{FF3FFF}
\definecolor{hoyegreen}{HTML}{31FF31}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
color=white,
width=\textwidth,
ybar, bar shift=0pt,
enlarge x limits=0.07,
ylabel={Free Energy Difference (\si{\kcalpmole})},
ylabel/.style={color=white},
xtick={1,2a,2b,3,4a,4b,5a,5b,6a,6b,6c,7},
every axis/.style={color=white},
ymax=40,
ymin=-110,
xtick pos=left,
nodes near coords,
nodes/.style={color=white},
nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east,color=white},
symbolic x coords={1,2a,2b,3,4a,4b,5a,5b,6a,6b,6c,7}
]
\addplot[fill=hoyegreen,]
coordinates{
(1,-48.93)
(2b,-13.62)
(4b,-46.85)
(5b,-42.27)
(6b,-55.74)};
\addplot[fill=hoyemagenta]
coordinates{
(2a,-26.90)
(3,31.78)
(4a,-49.25)
(5a,-49.71)
(6a,-44.14)
(6c,-51.07)};
\addplot[fill=yellow]
coordinates{(7,-97.69)};
\end{axis}
\end{tikzpicture}
\end{document}
If you want to change the colour of an individual bar, you can use the approach described in your second link, but there were a couple of errors in the code.
\documentclass{memoir}
\usepackage[left=1.5in, right=1in, top=1in, bottom=1in, headsep=0.1in, head=0.4in, includehead, includefoot, marginparsep=0in, marginparwidth=0in,footskip=0.4in]{geometry}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{filecontents}
\pagecolor{black}
\pgfplotsset{width=7cm,compat=1.5.1}
\usepackage{siunitx}
\sisetup{inter-unit-product={}\cdot{},sticky-per=true,multi-part-units=single,separate-uncertainty=true,list-units=single,range-units=single,detect-all,detect-weight=true,detect-inline-weight=math}
\DeclareSIUnit\calorie{cal}
\DeclareSIUnit\kcal{\kilo\calorie}
\DeclareSIUnit\kcalpmole{kcal\per\mole}
\definecolor{hoyemagenta}{HTML}{FF3FFF}
\definecolor{hoyegreen}{HTML}{31FF31}
\pgfplotsset{
discard if/.style 2 args={
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\def\pgfmathresult{inf}
\fi
}
},
discard if not/.style 2 args={
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}
\begin{document}
\begin{filecontents}{data.csv}
{Compound},{Energy}
1,-48.93
2a,-26.90
2b,-13.62
3,31.78
4a,-49.25
4b,-46.85
5a,-49.71
5b,-42.27
6a,-44.14
6b,-55.74
6c,-51.07
7,-97.69
\end{filecontents}
\pgfplotstablegetrowsof{data.csv}
\begin{tikzpicture}
\begin{axis}[
color=white,
width=\textwidth,
ybar,/pgf/bar shift=0pt,
enlarge x limits=0.07,
ylabel={Free Energy Difference (\si{\kcalpmole})},
ylabel/.style={color=white},
every axis/.style={color=white},
ymax=40,
ymin=-110,
xtick pos=left,
nodes near coords,
nodes/.style={color=white},
nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east,color=white},
xtick={1,...,11},
xticklabels={1,2a,2b,3,4a,4b,5a,5b,6a,6b,6c,7}
]
\addplot[fill=hoyegreen, discard if not={Compound}{4b}] table[x expr=\coordindex, col sep=comma]{data.csv};
\addplot[fill=hoyemagenta, discard if={Compound}{4b}] table[x expr=\coordindex, col sep=comma]{data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
Something like this if I understand correctly