
私は同様にプロットを作成したいと思います 棒グラフの例ただし、棒グラフではなく箱ひげ図を使用します。
これまでのところ、この MWE について私が持っているものは次のとおりです。
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\begin{document}
\pgfplotstableread{
%\begin{filecontents}{test.dat}
error
1
2
3
5
5
5
5
5
5
15
%\end{filecontents}
}\mytable
%Define the color series
\definecolor{RYB1}{RGB}{230,97,1}
\definecolor{RYB2}{RGB}{200,150,250}
\pgfplotscreateplotcyclelist{colorbrewer-RYB}{
{RYB1!50!black,fill=RYB1},
{RYB2!50!black,fill=RYB2}} %Do not add a comma after the last element of the list!
%Define the width of the boxes
\def\boxwidth{0.75}%
\begin{tikzpicture}
\begin{axis}[
scale only axis,
axis on top,
ymin=0, ymax=20,
ylabel={Error [m]},
boxplot/draw direction=y,
cycle list name=colorbrewer-RYB,
xtick={1.5, 4.5},
xticklabels={Group A, Group B},
tick align=inside,
xtick style={draw=none},
legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1},
legend image code/.code={
\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
]
%Group A
\addplot+[
boxplot={
draw position=1,
average, % <---- Where is the average?
box extend=\boxwidth
},
]
table[ y index=0, row sep=newline ]{\mytable}; % <---- Where are the outliers?
\addlegendentry{Yes\;};
\addplot+[
boxplot={
draw position=2,
every average, % <---- This was a desperate try with a surprising result
box extend=\boxwidth
},
]
table[ y index=0, row sep=newline ]{\mytable};
\addlegendentry{No\;};
%Group B
\addplot+[
boxplot prepared={draw position=4,
lower whisker=2.5,
lower quartile=4,
median=5,
average=6,
upper quartile=8,
upper whisker=9,
box extend=\boxwidth,
}
]
coordinates {(0,12) (0,10)};
\addplot+[
boxplot prepared={draw position=5,
lower whisker=2.5,
lower quartile=4,
median=8.5,
average=10,
upper quartile=12,
upper whisker=15,
box extend=\boxwidth,
},
]
table[row sep=\\,y index=0] { 0\\ 14\\ 15\\ };
\end{axis}
\end{tikzpicture}
\end{document}
その結果
追加/機能リクエスト
棒グラフと同じように、このタイプのグループ化されたボックス プロットを作成できれば便利です。これらのプロットでは、一連のシンボリック座標を指定し、それらの座標を使用して棒を追加するだけです。同じ座標を持つ棒はグループを形成し、間隔は自動的に適切に処理されます。
提示された MWE では、多くの次元量はすべて手動で定義されています。可能であれば、たとえば のような方法を使用して、希望の高さと幅を定義すると自動的に拡大縮小されるように図を作成できれば、
\setlength\figureheight{1.5in}% \setlength\figurewidth{1.5in}%
長さを手動で変更する必要がなくなります。この目的のために、シンボリック座標を使用してボックスを追加できると便利だと思います。
提示されたMWEの問題点
最初の 2 つのプロット (グループ A) のデータは同じテーブルから取得されますが、他の 2 つのボックス (グループ B) は準備されています。前の図には次の問題があります (解決方法がわかりません。明らかに何か間違っています...)
平均値に関する問題
- 最初のボックスでは、平均をプロットする目的で「平均」オプションを使用しましたが、機能しません。
- 2 番目では、代わりに (偶然に)「すべての平均」を使用しようとしましたが、驚くべき結果になりました。外れ値がプロットされるのです。
平均を正しくプロットするにはどうすればよいでしょうか? 可能であれば、形状を選択できるようにします (すべてのボックスで同じ形状)。
外れ値に関する問題
また、すべてのボックスの外れ値をプロットし、可能であれば形状を選択できるようにしたいと考えています(すべてのボックスで同じ)。
最初の 2 つのプロットの場合、テーブルからインポートされた生データなので、外れ値の計算は自動的に行われると思います。適切なオプションを追加する必要があるかもしれません... どのように追加するのでしょうか?
準備されたプロットの場合、座標とテーブルを追加しようとしましたが、成功しませんでした。何が足りないのでしょうか?