2 # Example of using histogram modes
5 set title "US immigration from Europe by decade"
6 set datafile missing "-"
7 set xtics nomirror rotate by -45
9 # First plot using linespoints
10 set style data linespoints
11 set key autotitle columnhead
12 plot 'immigration.dat' using 2:xtic(1), \
13 '' u 3, '' u 4, '' u 5, '' u 6, \
14 '' u 7, '' u 8, '' u 9, '' u 10, \
15 '' u 11, '' u 12, '' u 13, '' u 14, \
16 '' u 15, '' u 16, '' u 17, '' u 18, \
17 '' u 19, '' u 20, '' u 21, '' u 22
19 pause -1 "<cr> to plot the same data as a histogram"
21 set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
24 set style data histogram
25 set style histogram cluster gap 1
26 set style fill solid border -1
28 set xtic rotate by -45
30 plot 'immigration.dat' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col
32 pause -1 "<cr> to change the gap between clusters"
34 set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)"
35 set style histogram gap 5
38 pause -1 "<cr> to plot the same dataset as stacked histogram"
43 set title "US immigration from Europe by decade\nPlot as stacked histogram"
44 set key invert reverse Left outside
45 set key autotitle columnheader
49 set xtics nomirror rotate by -45
50 set style data histogram
51 set style histogram rowstacked
52 set style fill solid border -1
55 plot 'immigration.dat' using 2:xtic(1), \
77 pause -1 "<cr> to rescale each stack to % of total"
79 # Stacked histograms by percent
81 set title "US immigration from Europe by decade\nFraction of total plotted as stacked histogram"
82 set key invert reverse Left outside
84 set ylabel "% of total"
88 set style data histograms
89 set style histogram rowstacked
90 set style fill solid border -1
93 plot 'immigration.dat' using (100.*$2/$24):xtic(1) title column(2), \
94 '' using (100.*$3/$24) title column(3), \
95 '' using (100.*$4/$24) title column(4), \
96 '' using (100.*$5/$24) title column(5), \
97 '' using (100.*$6/$24) title column(6), \
98 '' using (100.*$7/$24) title column(7), \
99 '' using (100.*$8/$24) title column(8), \
100 '' using (100.*$9/$24) title column(9), \
101 '' using (100.*$10/$24) title column(10), \
102 '' using (100.*$11/$24) title column(11), \
103 '' using (100.*$12/$24) title column(12), \
104 '' using (100.*$13/$24) title column(13), \
105 '' using (100.*$14/$24) title column(14), \
106 '' using (100.*$15/$24) title column(15), \
107 '' using (100.*$16/$24) title column(16), \
108 '' using (100.*$17/$24) title column(17), \
109 '' using (100.*$18/$24) title column(18), \
110 '' using (100.*$19/$24) title column(19), \
111 '' using (100.*$20/$24) title column(20), \
112 '' using (100.*$21/$24) title column(21), \
113 '' using (100.*$22/$24) title column(22), \
114 '' using (100.*$23/$24) title column(23)
116 pause -1 "Now try histograms stacked by columns"
119 # xtic labels should be picked up from column heads ('title column')
120 # key titles should be picked up from row heads ('key(1)')
122 set title "Immigration from Northern Europe\n(columstacked histogram)"
123 set style histogram columnstacked
126 set ylabel "Immigration by decade"
127 set xlabel "Country of Origin"
131 set xtics norotate nomirror
132 plot 'immigration.dat' using 6 ti col, '' using 12 ti col, \
133 '' using 13 ti col, '' using 14:key(1) ti col
135 pause -1 "Next we do several sets of parallel histograms"
137 # 'newhistogram' keyword to plot
139 set title "Immigration from different regions\n(give each histogram a separate title)"
141 set key autotitle columnhead
142 set style histogram clustered gap 1 title offset 2,0.25
143 set style fill solid noborder
146 set xtics nomirror rotate by -45
147 set xlabel "(note: histogram titles have specified offset relative to X-axis label)" offset 0,-2
152 newhistogram "Northern Europe", \
153 'immigration.dat' using 6:xtic(1), '' u 13, '' u 14, \
154 newhistogram "Southern Europe", \
155 '' u 9:xtic(1), '' u 17, '' u 22, \
156 newhistogram "British Isles", \
157 '' u 10:xtic(1), '' u 21
159 pause -1 "Same plot using rowstacked histogram"
161 set style histogram rows
163 set yrange [0:900000]
164 set xlabel "(Same plot using rowstacked rather than clustered histogram)"