You can use point meta
to perform the multiplication by 100 and
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}
to add the percentage sign:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S\&P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=0.5,
point meta={x*100},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
nodes near coords align={horizontal}
]
\addplot
[draw=blue,pattern=horizontal lines light blue]
coordinates
{(0.17,Sales) (0.24,Marketing) (0.31,Finance) (0.42,Operations)};
\end{axis}
\end{tikzpicture}
\end{document}
If you also want this formatting for the x tick labels, then you can use
xticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
(no need to explicitly give the labels):
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines*=left,
title=Histogram of S\&P 500 CEOs Past Experience,
xbar,
width=8cm,
height=5cm,
xlabel={},
symbolic y coords={Sales, Marketing, Finance, Operations},
ytick=data,
xmin=0,
xmax=0.5,
xticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
point meta={x*100},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%},
nodes near coords align={horizontal},
]
\addplot
[draw=blue,pattern=horizontal lines light blue]
coordinates
{(0.17,Sales) (0.24,Marketing) (0.31,Finance) (0.42,Operations)};
\end{axis}
\end{tikzpicture}
\end{document}
You have also to specify an anchor
of your legend in this way:
legend style={at={(0.03,0.5)},anchor=west}
the anchor
define what point of the legend box will be placed at the coordinates you define with at={(<>,<>)}
.
If you use only at={(<>,<>)}
the coordinates you insert are that of the axis box where the point (0,0)
is the left bottom angle and (1,1)
the right top angle.
If you use instead at={(axis cs:<>,<>)}
you specify the real coordinates of the axis, the same of your plot.
EXAMPLES
legend style={at={(axis cs:0.5,1)},anchor=south west}
gives:
legend style={at={(1,1)},anchor=north east}
gives:
EDIT
The pgfplots manual
says:
The default position is north east
. This means that north east
correspond to a legend at a distance from axes of 2% the axes length. I imagine it is the same for the south west
position, in that case it corresponds to:
legend style={at={(0.02,0.02)},anchor=south west}
Best Answer
To place the y axis in the right:
UPDATE
As @Jake explained, you need
enlargelimits=false
to "shift" the y axis till reach the plot.