I'm trying to visualize accumulated working hours for different projects in rows (Foo Stuff, Bar Stuff, ...), recorded by employees in columns (alice, bob, ...) in a CSV file like this:
id,title,alice,bob,charlie,diego
foo,Foo Stuff,2,,3,1
bar,Bar Stuff,1,5,,
baz,Baz Stuff,,1,8,5
My goal is to get a stacked bar histogram with x axis being the employees, y axis the accumulated work hours per employee. My current approach is this gnuplot (I'm using 5.4.3) script:
set datafile separator ','
set style data histograms
set style histogram columnstacked
set style fill solid noborder
set boxwidth 0.75
set xtics rotate by 90 right
set grid ytics linestyle 0
set key outside
set xlabel "Employee"
set ylabel "Working hours"
plot for [COL=3:*] 'example.csv' using COL title columnhead
I'm new to gnuplot and it's not that easy for me to extract everything from the documentation. My most important questions here are:
- How to get the xtic labels right? There's a double
diegoafter the last column. - How to get a nice legend with project names (2nd column)?

To your questions:
for [COL=2:*]creates this double "diego". Looks like a bug to me (maybe only together with stacked histogram style)You can avoid it by
for [COL=2:6]if you know the number of columns beforehandstatsstored in the variableSTATS_columns(checkhelp stats).with boxesand store the second column in the variabletwhich will be used for the title.Maybe there are shorter and smarter solutions, but check the following example as starting point. It works for gnuplot>=5.4.0, but for older versions there might be some other workarounds.
Script: (works for gnuplot>=5.4.0)
Attempt to explain the second part of the plot command:
every ::ROW::ROWlimits it to one single row (checkhelp every)t(...,NaN)(checkhelp operators binary) actually nothing is plotted, but a legend is created neverthelesstwill be use as legend title (this only works for gnuplot>=5.4.0)I still hope there is a "nicer" solution.
Result: