How can I create a boxplot for each x value?
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:
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)
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: