我正在尝试更好地对齐标题文本

我正在尝试更好地对齐标题文本

我制作了以下箱线图:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [title = {Lengths of Amplification and Deletion Regions},ylabel = {$log_{10}(Length)$},
    boxplot/draw direction=y,
    xtick={1,2,3},
    xticklabels={Amplification, Amplification (no genes), Deletion}
    ]
    \addplot+[mark = *, mark options = {red},
    boxplot prepared={
      lower whisker=2.217484,
      lower quartile=3.541535,
      median=3.944694,
      upper quartile=4.572695,
      upper whisker=5.826493
    }, color = red
    ] coordinates{(0,6.29165)(0,6.21436)};
    \addplot+[mark = *,mark options = {green},
    boxplot prepared={
      lower whisker=3.378943,
      lower quartile=3.759290,
      median=3.974834,
      upper quartile=4.272700,
      upper whisker=4.699447
    }, color = gree
    ] coordinates{(0,2.874482)(0,2.564666)(0,5.819792)};
    \addplot+[mark = *,mark options = {blue},
    boxplot prepared={
      lower whisker=4.691824,
      lower quartile=5.236792,
      median=5.533932,
      upper quartile=5.997152,
      upper whisker=7.125098
    }, color = blue
    ] coordinates{(0,7.309382)(0,7.535505)(0,7.171933)(0,7.388371)(0,7.361202)};
    \end{axis}
\end{tikzpicture}
\end{document}

得到:

在此处输入图片描述

我怎样才能使标题看起来像这样:

 Amplification   Amplification   Deletion
                    (no genes)

并且可能更小以避免重叠?

谢谢你!

答案1

添加x tick label style={font=\footnotesize, text width=3cm, align=center}到轴选项。它将缩小字体,并提供最大 3cm 的文本宽度,足以(genes)换行。

输出

图1

代码

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\usepgfplotslibrary{statistics}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [title = {Lengths of Amplification and Deletion Regions},ylabel = {$log_{10}(Length)$},
    boxplot/draw direction=y,
    xtick={1,2,3},
    xticklabels={Amplification, Amplification (no genes), Deletion},
    x tick label style={font=\footnotesize, text width=3cm, align=center},
    ]
    \addplot+[mark = *, mark options = {red},
    boxplot prepared={
      lower whisker=2.217484,
      lower quartile=3.541535,
      median=3.944694,
      upper quartile=4.572695,
      upper whisker=5.826493
    }, color = red
    ] coordinates{(0,6.29165)(0,6.21436)};
    \addplot+[mark = *,mark options = {green},
    boxplot prepared={
      lower whisker=3.378943,
      lower quartile=3.759290,
      median=3.974834,
      upper quartile=4.272700,
      upper whisker=4.699447
    }, color = green
    ] coordinates{(0,2.874482)(0,2.564666)(0,5.819792)};
    \addplot+[mark = *,mark options = {blue},
    boxplot prepared={
      lower whisker=4.691824,
      lower quartile=5.236792,
      median=5.533932,
      upper quartile=5.997152,
      upper whisker=7.125098
    }, color = blue
    ] coordinates{(0,7.309382)(0,7.535505)(0,7.171933)(0,7.388371)(0,7.361202)};
    \end{axis}
\end{tikzpicture}
\end{document}

相关内容