6
votes

I have a plot with a set of points for different x values: 5 points for x=0.5, 5 points for x=0.6, ..., 5 points for x=1.4, 5 points for x=1.6.

Now I want to create a boxplot for each of those x values. But somehow all my boxplots are at x=0.5. I want the boxplots to be created at the right x value. The distance between 2 x values can be different. My current x values are 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4 and 1.6, but they could also be different for a different plot. How would I do that?

This is the GNUPlot script for my points: https://dl.dropboxusercontent.com/u/26464165/Points.gnu

This is the GNUPlot script for my boxplots: https://dl.dropboxusercontent.com/u/26464165/Boxplots.gnu

Thanks for your time!

2
No, I want boxplots. I want to show how much the y-values vary for each x-value. It's about results of different test runs.John

2 Answers

9
votes

You must rearrange your data for the boxplots. The statistics are computed over complete columns. So, you must rearrange your data like:

# 1.0 1.2 1.4 ...
2.2 2.2 3.06
2.0 2.46 2.93
2.2 2.46 3.06
2.0 2.4 2.8
1.73 2.33 2.8

Then you can plot it with:

set style fill solid 0.25 border -1
set style boxplot outliers pointtype 7
set style data boxplot

set title 'My Plot' font 'Arial,14';
set xtics ('1.0' 1, '1.2' 2, '1.4' 3)
plot for [i=1:3] 'data.txt' using (i):i notitle

The result with 4.6.4 is:

enter image description here

Instead of writing the xtics manually, you could extract them (with Unix commandline tools), like shown e.g. in https://stackoverflow.com/a/10799204/2604213:

header = "`head -1 data.txt | cut -b 2-`"
set for [i=1:words(header)] xtics (word(header, i) i)
6
votes

Christoph's answer is fine if you know the number of levels (columns) and their names (xtics) ahead of time. Otherwise, http://soc.if.usp.br/manual/gnuplot-doc/htmldocs/boxplot.html gives a solution with the fourth field of the using statement (using x:data:width:level).

You put all of your data in one column, with an accompanying factor column giving the level for each datum:

2.2   1.0
2.2   1.2
3.06  1.4
2.0   1.0
...

The order the data appear in doesn't matter as long as the levels are correct. The level is converted to a string, which overrides the xtics.

Modifying Christoph's script,

set style fill solid 0.25 border -1
set style boxplot outliers pointtype 7
set style data boxplot

plot "data.txt" using (1):1:(0.5):2

will generate the following:

Boxplot generated with GNUPlot using a factor column