1

Say I have data that I want to separate into different bars, but one of the is subdivided, as in. For instance:

A1 : 4
B1 : 1 2

A2 : 3
B2 : 2 3

And then I want to have (only) the B bars to be stacked. For the data above the graph should look like:

          y
o         y
o y     o y
o y     o x
o x     o x
A B     A B

How can I do that? I can change the format of the input file (or even use multiple files if necessary), but I really would like to have the final graph with clusters of bars, where some of the bars of each cluster are stacked, others not.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Eduardo Bezerra
  • 1,923
  • 1
  • 17
  • 32

1 Answers1

1

Here is one possiblity how you can achieve that. For this you need to group the A* values together in the data file, followed by two new lines and then all B* values:

A1 4
A2 3


B1 1 2
B2 2 3

Separating the data sets with two new lines allows you to access them with the index statement. (Using two files would also work)

Then you plot the first histogram. This implicitely uses 0, 1 etc as x-values, but gives them the labels A1, A2. For the B* values you create a new histogram with newhistogram and set its first x-value with at to 0 plus one boxwidth.

set style data histogram
set style histogram rowstacked
box_wd = 0.3
set boxwidth box_wd
set style fill solid
unset key

plot 'file.txt' using 2:xtic(1) index 0, \
     newhistogram at box_wd, \
     'file.txt' using 2:xtic(1) index 1,\
     '' using 3 index 1

With 4.6.4 you get:

enter image description here

The only thing might be, that the key of the two histograms are separated by a new line.

Christoph
  • 47,569
  • 8
  • 87
  • 187