0
votes

I am trying to plot a bar chart/histogram that shows, for every point of the x axis, two bars, each of which is divided in three parts. Take the following dataset:

Min #   Max #   Avg #   Min %   Max %   Avg %
6       12      6.67    13      100     35.25
0       6       3       0       90      43.25
235     1243    553     66.67   100     83.43

The idea is that for each row, there will be a pair of vertical bars, with the left one representing the three # values and the right one representing the three % values. The values are made-up, but the scale is more or less the real one.

So far, I have managed to get the following script, which is a frankenstein of several online scripts I found:

set ytics 10 nomirror tc lt 1
set y2tics 100 nomirror tc lt 2
set yrange [0:120]
set y2range [0:1500]
set style fill solid border -1

plot "table2.dat" using 5:xticlabels(1) with boxes lt rgb "#40FF00" t "Max \%",\
 "" using 6 lt rgb "#406090" t "Avg \%",\
 "" using 4 with boxes lt rgb "#403090" t "Min \%"

This will plot out the following chart:

Chart

What I cannot seem to figure out is how to put the second bar for the first three columns. Ideally, that "X" would also be replaced by a dotted line cutting the bar. The reason for the two Y axes is that each bar follows a different scale, so the second bar would have to be proportional to the right-side y axis. Finally, I had to add that little "hack" of making yrange higher than 100 so that the bars would not "hit the top". If there is another way to do that, that'd be great.

Thanks in advance for any help that can be given, I am a complete newbie at gnuplot but since trying to make this chart using spreadsheet tools was an even bigger pain, I am hopeful that someone'll be able to help with at least some of those problems.

Edit.: I will take suggestions for a better title for this question.

1
burningcutlery.com/derek/bargraph/cluster_stacked.png burningcutlery.com/derek/bargraph/cluster_stacked.perf These two links appear to contain the beginnings of an answer, but they use the cumulative stacked bar, whereas I am looking for them to overlap (like in the example image in the question). I will continue to try and figure this out, but I wanted to put this out here to give a better understanding of the question.Fledgling Pidgeon
Out of curiosity: does it have to be stacked histograms? Usually you would use something like a candlestick plot to visualize ranges and a mean (and perhaps additional data)user8153

1 Answers

0
votes

You can get a little further by setting a boxwidth to 0.4 of the default width, and defining a function (I used f here) that converts your data in columns 1 to 3 into percentage values too, and explicitly providing an x coordinate with the syntax x:y and using $1 to refer to column 1 etc. $0 is the row.

set boxwidth 0.4 relative
f(y,max) = (y*100./max)

plot "table2.dat" \
 using 5:xticlabels(1) with boxes lt rgb "#40FF00" t "Max \%",\
 "" using 6  lt rgb "#406090" t "Avg \%",\
 "" using 4 with boxes lt rgb "#403090" t "Min \%",\
 "" using ($0-.5):(f($2,$2)) with boxes lt rgb "red" t "Max",\
 "" using ($0-.5):(f($3,$2))  lt rgb "blue" t "Avg",\
 "" using ($0-.5):(f($1,$2)) with boxes lt rgb "orange" t "Min"

I used some garish colours to show the new boxes: enter image description here