I am currently producing the following chart:
With this code:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{pdfpages}
\pgfplotsset{compat=1.8}
\usepackage{color} % colors
\usepackage{xcolor} % more control over colors
\newcommand{\titlecolour}{blue!70!white}
% chart 1 data
\pgfplotstableread[col sep=comma]% % <---
{
country, 3Q19, 4Q19
US, 2.0, 1.9
Euro, 1.2, 1.1
PR China, 6.1, 6.0
Singapore, 0.2, 0.1
Indonesia, 5.1, 5.0
Malaysia, 4.7, 4.4
Korea, 2.1, 2.0
Taiwan, 1.7, 2.9
Philippines, 5.6, 5.9
}\chartone
\pgfplotsset{compat=1.11,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw[ ##1,/tikz/.cd,yshift=-0.25em]
(0cm,0cm) rectangle (0.6em,0.6em);},
},
}
\begin{document}
\begin{tikzpicture}
\small
\begin{axis}[
x=9mm,
ybar,
x = 0.85cm,
bar width = 2mm,
axis lines=left,
enlarge x limits=0.1,
enlarge y limits={.2, upper},
%
% y and x axis ticks
y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1,
/tikz/.cd, font=\scriptsize},
ymin = 0,
xtick=data,
x tick label style={rotate = 90},
symbolic x coords={US, Euro, PR China, Singapore,
Indonesia, Malaysia, Korea, Taiwan, Philippines},
%
% legends and labels
legend style={draw=none, legend columns=-1, at={(0.8, 1)},anchor=north east, %
/tikz/every even column/.append style={column sep=1em}}, % <---
y label style={at={(0.15,1)},rotate=-90,anchor=south}, % I prefer label along y axes
nodes near coords style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1,
/tikz/.cd, font=\scriptsize, color = black},
legend style={legend columns=-1},
ylabel={Annual change (\%)},
]
\addplot[\titlecolour, fill = \titlecolour]
table [y=3Q19] \chartone; % <---
\addplot[yellow!80!black, fill = yellow!80!black, nodes near coords]
table [y=4Q19] \chartone; % <---
\legend{~3Q19, ~4Q19}
\end{axis}
\end{tikzpicture}
\end{document}
I'd like to make two adjustments:
- Raise the
nodes near coordsslightly, so they aren't so close to the bars. - Set the values of the legend labels (3Q19 and 4Q19) as well as the x axis labels directly from the
chartonetable. Currently, they're being set manually, with the\legendandsymbolic x coordscommands, which is not ideal as it leaves room for human error.
Greatly appreciate any help!


