set xrange [-.5:3.5] set yrange [0:] set style fill solid plot "<sed 'G;G' test.dat" i 0 u (column(-2)):2:xtic(1) w boxes ti "Critical" lc rgb "black",\ "<sed 'G;G' test.dat" i 1 u (column(-2)):2:xtic(1) w boxes ti "High" lc rgb "red" ,\ "<sed 'G;G' test.dat" i 2 u (column(-2)):2:xtic(1) w boxes ti "Medium" lc rgb "green",\ "<sed 'G;G' test.dat" i 3 u (column(-2)):2:xtic(1) w boxes ti "Low" lc rgb "blue"
This takes up sed
and triple the space of your file, so gnuplot sees each line as a different data set (or "index"). You can build each index separately using index <number>
or i <number>
for brevity, as I did. In addition, the index number is available as column(-2)
, since we correctly distribute the fields.
Perhaps a slightly cleaner (gnuplot only) solution uses filters:
set xrange [-.5:3.5] set yrange [0:] set style fill solid CRITROW(x,y)=(x eq "Critical") ? y:1/0 HIGHROW(x,y)=(x eq "High") ? y:1/0 MIDROW(x,y) =(x eq "Medium") ? y:1/0 LOWROW(x,y) =(x eq "Low") ? y:1/0 plot 'test.dat' u ($0):(CRITROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "black" ti "Critical" ,\ '' u ($0):(HIGHROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti "High" ,\ '' u ($0):(MIDROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "green" ti "Medium" ,\ '' u ($0):(LOWROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "blue" ti "Low"
This solution also does not depend on any particular order in your data file (therefore I prefer it to a slightly different solution. Here we execute the column(0)
(or $0
) interval, which is the number of the record in the data set (in this case, the line number )
source share