1

I am using feedgnuplot to create a barchart, in order to visually show how teams compare to each other (I'd use the term benchmarking, but that's not a suitable tag here). What I would like to do is to colour one or more bars to indicate which team I'm working with.

Since pictures explain more, here is an example visually that I am attempting to reproduce: Benchmarking Plot

Here we have several components: Firstly the horizontal line indicating the "group mean", and then four specific teams -- two of which are over-performing, and two of which are under.

Can you help with the red bars please?

Current attempt is produced with:

< ../gnuplot.csv /usr/bin/feedgnuplot --set 'style data histograms' --set 'style fill solid border lt -1' -xticlabels

The gnuplot command this generates is:

set grid
set boxwidth 1
histbin(x) = 1 * floor(0.5 + x/1)
set style data histograms
set style fill solid border lt -1
plot '-'    using 3:xticlabels(2) notitle  
2 "E" 8
3 "H" 7
4 "B" 6
5 "F" 5
6 "A" 4
7 "D" 3
8 "C" 2
e
Phil
  • 23
  • 4
  • How does your input data look like? Can you please provide some example data? How do you specify the 4 bars, by x-value? What have you tried so far? How does your gnuplot script look like? – theozh Jan 26 '23 at 18:27
  • How to specify the bars? Any way possible (unsure of where to start). Ideally, as simple as possible. This is to be done via shell script. I can easily add an extra column to the data, with a boolean value or similar. – Phil Jan 26 '23 at 21:53

1 Answers1

0

From your example I don't see why you would need plotting style histogram. A simple bar chart with conditional color should be sufficient.

  • simply define a function based on your condition for bar coloring and use variable linecolor (check help lc variable).
  • if you want to plot the statistical mean value, use stats (check help stats).
  • the example below has just two columns column 1 text and column 2 numbers. Since you need an x-value for the bars, you take pseudocolumn 0, which is basically the row number with 0-based index (check help pseudocolumns).

Script:

### bar chart with conditional color
reset session

# create some random test data
set table $Data
    set samples 26
    y0 = 900
    alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    plot '+' u (alphabet[$0+1:$0+1]):(y0=y0-rand(0)*50) w table
unset table

myColor(col) = (_s=strcol(col), _s eq "C" || _s eq "J" || _s eq "T" || _s eq "X" ? \
                 0xff3333 : 0x3333ff)

set offset 1,1,0,0
set key noautotitle
set style fill solid 0.5
set yrange[0:1000]

stats $Data u 0:2 nooutput   # get the mean value into variable STATS_mean_y
set label 1 at STATS_max_x, STATS_mean_y sprintf("mean=%.1f",STATS_mean_y) offset 0,0.7 right

plot $Data u 0:2:(myColor(1)):xtic(1) w boxes lc rgb var, \
     STATS_mean_y w l lw 2 lc "web-green"
### end of script

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72