Search code examples
gnuplot

gnuplot: Histogram Required with stacked bars


Output Should be something like this

can anyone please help me with a sample code to build histogram for below data. I am very new to this and would really appreciate some help.

Date_Stat   Total   Success Gen_decline Failure_incomplete
01.05.2018  42045   39164   2096    785   
02.05.2018  33721   30857   1727    1137
03.05.2018  28159   26042   1513    604

Solution

  • It doesn't look to good, but it is a start. First I saved the data into a file "so-dat.txt" pretty much as shown. Then I used this gnuplot script.

    set boxwidth 0.9 absolute
    set style fill   solid 1.00 border lt -1
    set key right top vertical Right noreverse noenhanced autotitle nobox
    set style histogram clustered gap 1 title textcolor lt -1
    set datafile missing '-'
    set style data histograms
    set xtics border in scale 0,0 nomirror rotate by -45  autojustify
    set xtics  norangelimit 
    set xtics   ()
    set title "data" 
    set yrange [ 0.00000 : 45000. ] noreverse nowriteback
    ## Last datafile plotted: "immigration.dat"
    plot 'so-dat.txt' using 2:xtic(1) ti col, '' u 3 ti col, '' u 4 ti col, '' u 5 ti col
    

    That creates a bar chart with 3 clusters (by date) of four columns (Total Success Gen_decline failure_incomplete.)

    To make the key horizontal.

    set key right horizontal noenhanced autotitle nobox
    

    Or even set the key above. Although that is above the title.

    set key above horizontal autotitle nobox