Customize a histogram grouped by additional column
I am having trouble plotting a data file like this as a grouped bar chart.
x-axis group y-axis
1 11 0.1123
1 22 0.1687
1 33 0.1312
2 11 0.4567
2 22 0.4578
2 33 0.7465
3 11 0.7532
3 22 0.7742
3 33 0.7123
So, I would like the histogram to be the x-axis relative to the y-axis, but inside each x-axis "axis" there are 3 different columns, one for each group, like this image:
I can get a histogram of x versus y using plot 'file.dat' using 1:3
but cannot get it to group by the second column. How to do it?
+3
source to share
1 answer
The way I would go about it is to reformat the data in the columns like this:
x-axis group11 group22 group33
1 0.1123 0.1687 0.1312
2 0.4567 0.4578 0.7465
3 0.7532 0.7742 0.7123
Then this is a normal gnuplot bar chart.
set style fill solid 1.00 border -1
set style data histogram
set style histogram cluster gap 2
plot 'data2.dat' using 2 t "11", '' using 3 t "22", '' using 4:xtic(1) t "33"
The result looks like this:
+4
source to share