I created the following histogram but all labels were messed up.
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{
compat=newest,
xlabel near ticks,
ylabel near ticks
}
\begin{document}
\begin{tikzpicture}[font=\small]
\begin{axis}[
ybar,
bar width=20pt,
ymin=0,
%ymax=100,
xtick=data,
axis x line=bottom,
axis y line=left,
enlarge x limits=0.2,
symbolic x coords={First Variable, Second Variable, Third Variable, Fourth Variable, Fifth Variable},
xticklabel style={anchor=base,yshift=-\baselineskip},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}
]
\addplot[fill=orange,fill opacity=0.5, text opacity=1] coordinates {
(First Variable,42)
(Second Variable,36)
(Third Variable,23)
(Fourth Variable,22)
(Fifth Variable,61)
};
\end{axis}
\end{tikzpicture}
\end{document}
Then I shortened the labels to fit them well but it required me to add the legend. But the legend is just giving one label, not others. I need help regarding either fitting the labels or explaining the labels in the legend.
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{
compat=newest,
xlabel near ticks,
ylabel near ticks
}
\begin{document}
\begin{tikzpicture}[font=\small]
\begin{axis}[
ybar,
bar width=20pt,
ymin=0,
%ymax=100,
xtick=data,
axis x line=bottom,
axis y line=left,
enlarge x limits=0.2,
symbolic x coords={A, B, C, D, E},
xticklabel style={anchor=base,yshift=-\baselineskip},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}
]
\addplot[fill=orange,fill opacity=0.5, text opacity=1] coordinates {
(A,42)
(B,36)
(C,23)
(D,22)
(E,61)
};
\legend{A=First Variable, B=Second Variable, C=Third Variable, D=Fourth Variable,E=Fifth Variable}
\end{axis}
\end{tikzpicture}
\end{document}
