3

I have a data file similar to the one below (there are totally 10 rows):

1.5  1.6  3.0  4.0  1.2  1.3
1.7  1.1  2.6  3.4  1.5  1.6
......

Each row is corresponding to the results of 3 methods on a dataset, where the first two values are for the first method, the next two for the second method and the last two for the last method. I want to generate a stacked bar diagram, such that

  • For each dataset, there would be 3 bars, each corresponding to a method;

  • For each method, its bar is split into two, where the bottom (resp. top) one represents the first (resp. second) value;

  • The color of the bar for a method is different from that of another method.

More specifically, I want a diagram like link (Sorry, I do not have enough reputations to show a picture here.)

How can I achieve this using GNUPlot?

addddddc
  • 33
  • 2

1 Answers1

2

This task is a bit too complex for gnuplot's histogram, because you combine clustering and stacking. I think, that for you it is most appropriate to draw each box part manually with the boxxy style:

unset key
set xtics 1,4
set for [i=0:9] xtics add (sprintf("data %d", i + 1) i*4 + 1)
set style fill solid noborder
set style data boxxy
set autoscale xfix

set linetype 1 lc rgb "#9400D3"
set linetype 2 lc rgb "#009E73"
set linetype 3 lc rgb "#56B4E9"
set linetype 4 lc rgb "#B46AD3"
set linetype 5 lc rgb "#64C4AA"
set linetype 6 lc rgb "#8BC8EC"

plot for [i=0:2] "file.dat" u ($0 * 4 + i):(0.5*column(2*i + 1)):(0.5):(0.5*column(2*i+1)),\
     for [i=0:2] "file.dat" u ($0 * 4 + i):(0.5*column(2*(i+1)) + column(2*i + 1)):(0.5):(0.5*column(2*(i+1)))

The set for adds the labels manually on the centre bar for each row.

The first plot line plots the bottom values of each bar, the second line plots the top values.

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187