1
votes

My data file looks like this

A 20120301 4
A 20120302 3
B 20120301 5
B 20120302 6
C 20120303 5

except there are many more than just A,B,C and I want to create a stacked graph with gnuplot (similar to the "Stacked histograms" from the gnuplot demos)

20120301 = (A:4 + B:5)
20120302 = (A:3 + B:6)
20120303 = (C:5)

So far I could not convince plot to read the data in that format. Do I have re-arrange the data file for this? Or is there a way for gnuplot to read the data in that format?

1
I'm having a hard time figuring out which elements you want stacked from your description. Is each row corresponding to a stack of boxes? e.g. B:5 is stacked on A:4 in the 20120301 column? If so, what is the significance of the letter (A,B,C). Is that supposed to correspond to the color of the box? - mgilson
@mgilson Yes, you got that right. A-C are types (and hence colors). In my example you should see 3 stacked columns with the total heights of 9, 9, 5. The first two columns should be made of two boxes that are A and B. - tcurdt

1 Answers

1
votes

I think I've managed to beat it into a form that will work (you'll need at least gnuplot 4.3):

set boxwidth 0.75 absolute
set style fill   solid 1.00 border lt -1
set datafile missing '-'
set style histogram rowstacked
set style data histograms
set yrange [0:]
plot for [i=2:4] 'test.dat' u i,'' u (0.0):xtic(1) notitle

and here's the datafile test.dat

#date     A B C
#missing data is marked by a minus sign
20120301  4 5 -   
20120302  3 6 -
20120303  - - 5

Phew! I've never been much good with gnuplot when it comes to histograms. Hopefully this will work for you (Sorry about the change to your datafile).