2

I wonder how to use gnuplot to plot this figure: enter image description here

There are two problems I have:

  • the ytic is ..., 10^2, 10^1, 10^2, 10^3, ... How to handle such a case?
  • I know gnuplot support boxplot, but how to regroup boxplot according to some label?

Since I don't have the original data for the figure, I make up some data by myself.

There are two companies A, B, and C, selling different fruits with four prices.

Apple prices of company A: 1.2 1.3 1.4 1.1

Banana prices of company A: 2.2 2.1 2.4 2.5

Orange prices of company A: 3.1 3.3 3.4 3.5

Apple prices of company B: 1.2 1.3 1.4 1.1

Banana prices of company B: 2.2 2.1 2.4 2.5

Orange prices of company B: 3.1 3.3 3.4 3.5

Apple prices of company C: 2.2 1.3 1.4 2.1

Banana prices of company C: 3.2 3.1 3.4 2.5

Orange prices of company C: 2.1 3.3 1.4 2.5

I wonder how to plot those numbers by gnuplot.

changye
  • 23
  • 3
  • 2
    What have you tried so far? How does your (non-working) code and result look like? How does your data look like? Please always include data and code to questions. – theozh Nov 01 '21 at 07:42
  • This figure is from an academic paper, which I do not have data. I am not sure whether it is made by gnuplot as well. But I want to know if gnuplot can plot this kind of figure. – changye Nov 01 '21 at 10:57
  • 2
    Have you tried code from e.g. here: https://stackoverflow.com/questions/32059901/boxplot-in-gnuplot-how-to-plot-different-groups-in-one-boxplot?rq=1 Please first try to create a plot by your own, and then ask about the remaining problems that you can't solve. – Eldrad Nov 01 '21 at 13:24
  • @changye thanks for adding example data. If you had checked `help boxplot` you would have noticed that your format is not ideal because gnuplot prefers data in columns (especially for boxplots). Is your data fixed or can it be changed to a different (column) format? – theozh Nov 01 '21 at 18:41

1 Answers1

1

Your question is not very detailed and your own coding attempt is missing, hence, there is a lot of uncertainty. I guess there is no simple single command to get your grouped boxplots. There are for sure several ways to realize your graph, e.g. with multiplot.

The assumption for the example below is that all files have the data organized in columns and equal number of columns and same fruits in the same order. Otherwise the code must be adapted. It all depends on the degree of "automation" you would like to have. Vertical separation lines can be drawn via headless arrows (check help arrow). So, see the following example as a starting point.

Data:

'Company A.dat'

Apples   Bananas   Oranges
1.2      2.2       3.1
1.3      2.1       3.3
1.4      2.4       3.4
1.1      2.5       3.5

'Company B.dat'

Apples   Bananas   Oranges
1.2      2.2       3.1
1.3      2.1       3.3
1.4      2.4       3.4
1.1      2.5       3.5

'Company C.dat'

Apples   Bananas   Oranges
2.2      3.2       2.1
1.3      3.1       3.3
1.4      3.4       1.4
2.1      2.5       2.5

Code:

### grouped boxplots
reset session

FILES     = 'A B C'
File(n)   = sprintf("Company %s.dat",word(FILES,n))
myXtic(n) = sprintf("Company %s",word(FILES,n))

set xlabel "Fruit prices"
set ylabel "Price"
set yrange [0:5]
set grid y

set key noautotitle
set style fill solid 0.3

N    = words(FILES)    # number of files
COLS = 3               # number of columns in file
PosX = 0               # x-position of boxplot

plot for [n=1:N] for [COL=1:COLS] PosX=PosX+1 File(n) u (PosX):COL w boxplot lc COL, \
     for [COL=1:COLS] File(1) u (NaN):COL w boxes lc COL ti columnhead, \
     for [n=1:N] File(1) u ((n-1)*COLS+COLS/2+1):(NaN):xtic(myXtic(n))
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72