Hot answers tagged

23

PGFPlots supports boxplots natively as of version 1.8 See Boxplot in LaTeX for an example. The remainder of this answer should be considered obsolete. You're right to ask about this, the current code is not very convenient to use (although it's proved surprisingly useful to me in the past nonetheless). Your approach is very attractive in how much simpler ...


22

Boxplots are described in chapter 5.9.1 of the PGFPLOTS manual. [EDIT chapter 5.12.1 as of pgfplots v. 1.13] Using your data with the examples in the manual I get: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.8} \usepgfplotslibrary{statistics} \begin{document} \begin{tikzpicture} \begin{axis} [ ytick={1,2,3}, ...


14

The table in an \addplot command using the boxplot plot type is only used for providing raw data (if using boxplot) or outlier data (if using boxplot prepared), but not the box parameters. Those always need to be provided directly using the boxplot prepared={...} options. You can, however, write a couple of wrapper styles that read the values from a table ...


11

Box plots are always placed at the coordinate specified with boxplot/draw position. This, in turn, defaults to 1+\plotnumofactualtype, but it can be customized to other values. In your case, you can simply place all your plots into one axis and assign an individual boxplot/draw position to each. Here is an approach which defines a math expression which ...


8

This is what I've started using recently, since understanding more or less how to use the new boxplot interface of pgfplots. Although I know it's not particularly pretty (how could it be? I'm by no means an R programmer...), it does get the job done. But it would be interesting to see what others have come up with. EDIT: Since writing this answer, the ...


7

There is are some styles listed in the manual (page 432 of the latest version in TeX Live 2013, dated 28-2-2014) that can be used to style the boxplot. They are every boxplot, every box, every whisker, every average and every median. You can set them globally with e.g. \pgfplotsset{ boxplot/every whisker/.style={ultra thick,dashed,cyan} } or for a ...


6

As @darthbith said in his comment to my question: At a guess, its due to the cycle lists that pgfplots uses to pick the line styles. See page 173 of the 1.10 manual. – darthbith 7 hours ago Therefore, I took control of the cycle list (and added ymin/ymax values) to let the plot behave as I had originally intended, by adding line 15, cycle list={{red},{...


6

If you add the following code snippet to your preamble, you can use hide outliers to locally disable plotting the outliers: \makeatletter \pgfplotsset{ boxplot/hide outliers/.code={ \def\pgfplotsplothandlerboxplot@outlier{}% } } \makeatother \documentclass{article} \usepackage{pgfplots} \usepgfplotslibrary{statistics} \begin{document} \...


6

You can either adjust the width and height settings to change the aspect ratio of the plot, for example by setting it to width=12cm, height=6cm, or you can set the x unit vector length, for example to x=80cm. That way, the plot will automatically grow if you add more values: \documentclass{article} \usepackage{pgfplots} \usepackage{filecontents} \begin{...


6

To get a completely black box plot (including the marks for the outliers), the easiest thing is to use \addplot [mark=*, boxplot] (note the omission of the +). What the + does is indicate to PGFPlots that you want to use the style defined by the plot cycle list: by default, the first plot is blue, the second plot is red, and so on. That's not what you want ...


5

In principle, you can just provide one or more box plots here. In your case, it appears to be boxplot prepared with suitable arguments. I rarely had the opportunity to study common box plot styles, so I took the freedom to adopt pgfplots to your style. Maybe I can add such styles to pgfplots eventually, so feedback of sorts "I miss a style like XYZ" are ...


5

Without pgfplots you can insert chunks of R code directly in the text file and obtain the results of this chunks (text, tables or figures) instead of the R code in the PDF file. The source file must have the extension .Rnw (R noweb) that R with the Sweave fuction (or knitr) convert in a normal .tex that you compile as usual. If you use rstudio the ...


5

This is because of a "known" bug in floor (and int). Creating a custom Floor function and using this solves your problem. For details please have a look at the comments in the code. % used PGFPlots v1.16 \begin{filecontents*}{group1.csv} ac1,ac2,ac3,ac4,ac5 0.696969696969697,0.6515151515151516,0.7384615384615384,0.7384615384615384,0.7384615384615384 0....


4

Expanding my comment into an answer: The OP's quoted passage from the manual tells us that the key boxplot/every box is used to change fill colors. The important thing is to recognize that this is a style and must be modified as such. I used boxplot/every box/.style={fill=gray!50} to modify the style for every box in the boxplot. Simplified MWE: (Extra ...


4

Since version 1.8, PGFPlots can draw boxplots out of the box (pardon the pun). You can add the ability to draw notches relatively easily, and you can use the approach from Read boxplot prepared values from a table to provide the values from a table. The above image is generated using \pgfplotstableread{ lw lq med uq uw ln un 5 7 8.5 9.5 10 8....


4

Use coordinate (..) at (...); instead of node (..) at (...) {};, then the \draw works as expected. Another way is to change to \draw (A.center) -- (B.center) -- (C.center); while using node, then lines are drawn between the centers of the nodes, rather than edge to edge, as is the default. If you've defined a style in the axis options or with \pgfplotsset ...


4

There are at least two different factors potentially contributing to differences in the boxplots produced by Matlab and pgfplots. 1. <= and >= (Matlab) vs < and > (pgfplots) There is a difference in the definitions of whiskers and outliers. From the manual of pgfplots (I have emphasized the key fact): lower whisker is the smallest data ...


4

An answer is to set whisker range, which determines which points are considered outliers, to a very high value. \documentclass[12pt]{article} \usepackage{pgfplots} \usepackage{filecontents} \pgfplotsset{width=\textwidth, compat=1.12} \usepgfplotslibrary{statistics} %% A value larger than the ratio between any quartile range of any %% boxplot in the ...


4

To my knowledge you can change the whisker calculation only by using /pgfplots/boxplot/whisker range={⟨number⟩} %(initially 1.5) You find the documentation on page 477 of the manual linked in your question. However, ⟨number⟩ is not a percentage. Whiskers are calculated using the upper/lower quartile +/- ⟨number⟩ times the inter-quartile-range with ...


4

You can extend Jake's answer to Read boxplot prepared values from a table fairly easily, using \pgfplotsinvokeforeach. The code below is based on Jake's answer, with just a few modifications: a way of getting the number of rows from a table: \pgfplotstablegetrowsof{\datatable} \pgfmathtruncatemacro\TotalRows{\pgfplotsretval-1} Subtract one, because row/...


3

(Too long for a comment.) Your code seems to work fine, including annotations. \documentclass{article} \usepackage{filecontents} \usepackage{pgfplots, pgfplotstable} \usepgfplotslibrary{statistics} \begin{document} \pgfplotsset{width=7cm,compat=1.10} \pgfplotstableread{ %\begin{filecontents}{test.dat} miles 1 2 1 5 4 10 7 10 9 8 9 9 %\end{filecontents} ...


3

You need to make sure that both your axes have the same width. In this case, that means that you also need to put the x=0.5cm, enlarge x limits=0.05 that you use in the first axis into the options for the second axis. To get the label right, set compat=1.8 or newer: \documentclass{minimal} \usepackage{pgfplots} \usepackage{filecontents} \pgfplotsset{compat=...


3

Here's your example with a new optional key box plot width, which can be used to set the widths of the boxes: \documentclass{minimal} \usepackage{pgfplots} \usepackage{filecontents} \begin{filecontents}{testdata.dat} 0 1 1.2 0.4 1.5 0.2 1 2 2.3 1.5 2.7 1 2 0.7 1.4 0.5 1.9 0.1 3 1 1.2 0.4 1.5 0.2 4 2 2.3 1.5 2.7 1 5 0.7 1.4 0.5 1.9 0.1 \end{...


3

I discovered the bug of tikz: if you note, the wrong whiskers appear to have exactly the same value. Well if you try to calculate them manually they result both 0. What does it happen if one tries to plot a zero value on a log scale without any check? It happens this bug ;-) If you replace 0.000 values with 0.001 values, for example, the whiskers appear ...


3

Right after the coordinates for the boxplot, add the code for one of the nodes found in the example in the manual. I just changed left to above/below, and reduced the inner sep to get the number closer to the line. \documentclass[12pt,tikz,border=10pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{pgfplots.statistics} \...


3

Perhaps something like this, though some manual fiddling is required. Start by reducing the height of the boxes, by adding /pgfplots/boxplot/box extend=0.3 to the axis options. The default value is 0.8, adjust this to your liking. Then for each plot, set draw position to some value slightly above or below the tick value. E.g. draw position=1.2 and 0.8 as in ...


3

Addendum/New answer With the release of TikZ/PGF v3.1 the below mentioned bug is fixed and thus OPs example now works as expected. Old answer This is because of an already known bug in the mod function. To circumvent the problem I adjusted a solution that was originally given by Jake. % used PGFPlots v1.14 \documentclass[border=5pt]{standalone} \...


Only top voted, non community-wiki answers of a minimum length are eligible