![Gráfico de box plot - Nova linha para xticklabels longos](https://rvso.com/image/476268/Gr%C3%A1fico%20de%20box%20plot%20-%20Nova%20linha%20para%20xticklabels%20longos.png)
Quero fazer com que meus "xticklabels" tenham uma nova linha entre eles para que fiquem em duas linhas e não tão apertados. A barra invertida dupla \\ e \n não funcionou.
Código:
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
boxplot/draw direction=y,
axis y line=left,
enlarge y limits,
ylabel={Impact of latency},
xlabel={Game and latency},
ytick={1, 2, 3, 4, 5},
yticklabels={1, 2, 3, 4, 5},
ymajorgrids,
xtick={1, 2, 3, 4},
xticklabels={Chess 0ms , Chess 1000ms, Pong 0ms, Pong 1000ms},
]
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}
Responder1
Para quebrar linhas com \\
nós, você precisa definir seu alinhamento com align
. Adicionar
xticklabel style={align=center}
e você pode usar
xticklabels={Chess\\ 0ms, Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},
Exemplo completo (removi axis y line=left
, adicionei uma seta no lado esquerdo da caixa):
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
boxplot/draw direction=y,
enlarge y limits,
ylabel={Impact of latency},
xlabel={Game and latency},
ytick={1, 2, 3, 4, 5},
ymajorgrids,
xtick={1, 2, 3, 4},
xticklabels={Chess\\ 0ms, Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},
xticklabel style={align=center}
]
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}