
다음과 같은 플롯을 만들고 싶습니다. 막대 그래프 예, 그러나 막대 대신 상자 그림이 있습니다.
지금까지 내가 가지고 있는 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의 문제
처음 두 플롯(그룹 A)의 데이터는 동일한 테이블에서 가져온 반면, 나머지 두 플롯(그룹 B)의 상자는 준비됩니다. 이전 그림에는 다음과 같은 문제가 있습니다. (해결 방법을 모르겠습니다. 분명히 제가 뭔가 잘못하고 있는 것 같습니다...)
평균 문제
- 첫 번째 상자에서는 평균을 표시하려는 의도로 '평균' 옵션을 사용했지만 작동하지 않습니다.
- 두 번째에서는 (우연히) '모든 평균'을 대신 사용하려고 시도했는데 놀라운 결과가 나왔습니다. 이상값이 표시됩니다.
평균을 올바르게 표시하는 방법은 무엇입니까? 가능하면 모양을 선택할 수 있습니다(모든 상자에 대해 동일한 모양).
이상치 관련 문제
또한 가능한 경우 모양을 선택할 수 있도록(모든 상자에 대해 동일) 모든 상자의 이상값을 플롯하고 싶습니다.
처음 2개의 플롯의 경우 테이블에서 가져온 원시 데이터이므로 이상값 계산이 자동으로 수행되는 것 같습니다. 아마도 올바른 옵션을 추가해야 할 것 같습니다... 어떻게 추가하나요?
준비된 플롯의 경우 좌표와 테이블을 추가하려고 시도했지만 성공하지 못했습니다. 내가 무엇을 놓치고 있나요?