4

I'd like to draw in the same frame a given number of box plots with the macro \psBoxplot from the pst-plot package. I'm retrieving the sampled data from as many files as different box plots by using the macro \readdata. I'd like to use a single file to store the data sets for the different box plots, though.

By using the optional arguments of the \listplot macro I can plot a given number of curves based on different data sets stored in the same file-- the latter data sets only need to comprise different columns in the file. Now, how could I do something similar to this in order to draw box plots?

I believe no MWE is needed for this question, but if required I could provide one.

MWE (as per suggestion):

Let us say I have two data sets that I'm going to number and label by the corresponding numerals; e.g., '1' and '2'. I've stored data set 'i' in the file Data<i>.dat (i=1,2) and I can draw the box plots as follows:

\documentclass{article}

\usepackage{filecontents,pstricks,pst-plot}

\begin{filecontents*}{Data1.dat}
[98   20   79   14   23   21   58   13   19   53  41 11 83 71 10  89 10 46 76]
\end{filecontents*}

\begin{filecontents*}{Data2.dat}
[98   20   79   14   23   21   58   13   19   53  41   11 83 71 10 89 10 46 76]
\end{filecontents*}

\begin{document}

% Let us say my data are bounded between 10 and 100.
\psset{xunit=20mm,yunit=0.5mm}
\begin{pspicture}(0,0)(3,110)
\multido{\ind=1+1}{2}{%
    % Reading data from file
    \readdata{\Data}{Data\ind.dat}
    \rput{0}(\ind,0){\psBoxplot[barwidth=0.5\psxunit]{\Data}}
}
\end{pspicture}

\end{document}

With the MWE I generate the two data files Data1.dat and Data2.dat (right, they store the same data, but that's irrelevant here).

If I were to plot two curves (as opposed to box plots) in the same frame I could do it with \listplot, have the data sets stored in the same file comprising each data set one column, and use the options plotNo and plotNoMax. I'd like to be able to do something like this with box plots.

10
  • Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing what you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Commented Jun 30, 2013 at 20:14
  • @Henri Menke: I understand your point; it's only that my question is not about the plot itself, but just about how to retrieve the data from a single file as opposed to having to use as many different files as plots.
    – Marcos
    Commented Jun 30, 2013 at 20:33
  • It would still be helpful to see, for example, the formatting in one of your data file. As stated currently, it's really kind of difficult to figure out what you want. For example, are the "x"-values categorical or numerical. Do the same "x"-values have multiple "y" values for each of the plots you desire, etc. Show us something that you think should work, whether or not it does. Or show us something that you think would work if designers of the various packages thought exactly as you do. It'll help us understand how better to help you.
    – A.Ellett
    Commented Jul 1, 2013 at 0:06
  • provide also a simple data file.
    – user2478
    Commented Jul 1, 2013 at 12:55
  • @Herbert I have appended to the previous MWE a few lines in order to generate two data files. I hope this helps.
    – Marcos
    Commented Jul 1, 2013 at 17:52

2 Answers 2

1

PGFPlots can handle this. The datasets need to be in different columns, then you can select which dataset to process using y index=<column index>.

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}

\begin{filecontents*}{Data.dat}
98, 32
20, 11
79, 26
14, 9
23, 22
21, 10
58, 25
13, 8
19, 5
53, 29
41, 37
11, 2
83, 25
71, 51
10, 7
89, 17
10, 6
, 41
, 75
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[x=1cm, xtick={1,2}, mark=*]
\addplot [boxplot, draw direction=y] table [y index=0, col sep=comma] {Data.dat};
\addplot [boxplot, draw direction=y] table [y index=1, col sep=comma] {Data.dat};
\end{axis}
\end{tikzpicture}

\end{document}
3
  • Well, even though my heart is with PostScript ;-), I guess I already have reasons enough to paying more attention to TikZ-based resources. Right, your approach not only does what I need in a most elegant way, but it retrieves the data in a format like I was asking for. The only thing is that my question addressed a PSTricks-based macro, so maybe I should expand the scope of my question or see if I can in some way give the proper credit to your answer.
    – Marcos
    Commented Jul 7, 2013 at 17:44
  • @Marcos: Hehe, that's okay, you don't need to adapt your question or anything. It's become customary on this site to post PSTricks answers to TikZ questions and vice versa. Even if that might not help the asker that much, others coming across similar problems could benefit from seeing different approaches.
    – Jake
    Commented Jul 7, 2013 at 17:47
  • 1
    In any case it has proved to be helpful and, except for the restricted scope of my OP, it's a full-fledged answer. So I think it's only fair ticking the green mark. Thanks so much (even though I know that spending resources in this kind of open expression is discouraged in this forum ;-)).
    – Marcos
    Commented Jul 7, 2013 at 18:13
2
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{Data.dat}
98, 32
20, 11
79, 26
14, 9
23, 22
21, 10
58, 25
13, 8
19, 5
53, 29
41, 37
11, 2
83, 25
71, 51
10, 7
89, 17
10, 6
, 41
, 75
\end{filecontents*}
\usepackage{pst-plot}

\begin{document}
\begin{pspicture}(-1,-1)(5,6)
\psaxes[axesstyle=frame,dy=1cm,Dy=20,ticksize=4pt 0](0,0)(4,5)
\psreadDataColumn{1}{,}{\data}{Data.dat}
\rput(1,0){\psBoxplot[fillcolor=red!40,yunit=0.05]{\data}}
\psreadDataColumn{2}{,}{\data}{Data.dat}
\rput(3,0){\psBoxplot[fillcolor=blue!40,yunit=0.05]{\data}}
\end{pspicture}

\end{document}

enter image description here

5
  • you need the TL update from tomorrow or pst-plot.tex from texnik.dante.de/tex/generic/pst-plot.
    – user2478
    Commented Jul 10, 2013 at 14:49
  • The behaviour of the whiskers is inconsistent, both with the manual and within the plot. The top whisker seems to represent Q3+3/2*IQR, but the bottom whisker seems to represent the last data point that is greater than Q1-3/2*IQR. Only the bottom whisker behaves like described in the manual: "The 'whiskers' are lines to the farthest points that are not outliers (i.e., that are within 3/2 times the interquartile range of Q1 and Q3 )". The behaviour of the bottom whisker is the one that corresponds to common practice.
    – Jake
    Commented Jul 10, 2013 at 15:29
  • go to shodor.org/interactivate/activities/BoxPlot and put the data of the second column into the data fields and create the box plot with option "uncover outliers"
    – user2478
    Commented Jul 10, 2013 at 18:42
  • If I do not use the last two values 41 and 75 I get the same as you have ... But that is not the correct data set.
    – user2478
    Commented Jul 10, 2013 at 18:53
  • Use boxplot(c(32,11,26,9,22,10,25,8,5,29,37,2,25,51,7,17,6,41,75)) in R, or boxplot([32,11,26,9,22,10,25,8,5,29,37,2,25,51,7,17,6,41,75]) in Matlab, you'll get the same as in my answer. Or read the description at Wolfram MathWorld, or in the NIST Engineering Stats Handbook. The shodor.org implementation, like the PSTricks one, is non-standard.
    – Jake
    Commented Jul 10, 2013 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .