Gráfico de diagrama de caja: nueva línea para etiquetas xtick largas

Gráfico de diagrama de caja: nueva línea para etiquetas xtick largas

Quiero que mis "xticklabels" tengan una nueva línea entre ellas para que queden en dos líneas y no tan apretadas. La doble barra invertida \\ y \n no funcionó.

mi grafica

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}

Respuesta1

Para romper líneas con \\nodos, debe establecer su alineación con align. Agregar

xticklabel style={align=center}

y puedes usar

xticklabels={Chess\\ 0ms,  Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},

Ejemplo completo (lo eliminé axis y line=left, agrega una flecha en el lado izquierdo del cuadro):

\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}

Ejemplo completo

información relacionada