カテゴリカルデータの為の棒グラフを描いてく.
with boxesplot ..
using <x>:<y>{:xticlabels(<xlabel>)}{:yticlabels(<ylabel>)}
with boxes
で折れ線グラフが棒グラフになる. xticlabels とか xticlabel とか xtic はただの省略形で全て同じ意味.
set boxwidthset boxwidth <width> {relative|absolute}
棒の幅を指定できる. relative はデータ間隔に対する相対的な幅を指定し, absolute は今の x 軸に関して絶対的な幅を指定する. 特に対数スケールを x 軸に指定している場合に absolute を使うと幅にも対数スケールが適用されるので注意.
set boxwidth をしていない初期状態は set boxwidth 1 relative された状態になる. relative も absolute も指定せず set boxwidth <width> とした場合は absolute 扱いになる.
set style fillset style fill
{transparent} solid
{border lc rgb <color>}
| params | default | value | explanation |
|---|---|---|---|
| transparent | -- | -- | 透明度を有効にする (1.0 で不透明) |
| border | -- | -- | 棒の枠線を描画する |
| color | -- | (color) | 枠線の色 |
with boxes で描画される棒の塗りつぶしのスタイルを指定する. ただし, この color は枠線の色を指定するものであり, 塗りつぶしの色を指定するものではないことに注意. 塗りつぶしの色は fillcolor オプションや ls オプションで指定する.
with boxes fillcolorplot ..
with boxes fillcolor <color>
$data <<EOD
apple 100
banana 200
candy 250
EOD
set yrange [0:300]
set boxwidth 0.8 relative
plot $data with boxes
デフォルトではこんな見た目.
using によって \(x\) はデータの行番号 (0, 1, 2, ..), \(y\) は 2 列目の値 (100, 200, 250), xticlabel(1) ( xtic ) によって x 軸の目盛ラベルが 1 列目の値 (apple, banana, candy) になる.
$data <<EOD
apple 100
banana 200
candy 250
EOD
set yrange [0:300]
set boxwidth 0.8 relative
set style fill solid 0.8 border lc rgb 'black'
plot $data using 0:2:xtic(1) with boxes fillcolor '#55aaff'
set style によって枠線の色や塗りつぶしの透明度を指定. fillcolor によって塗りつぶしの色を指定した.
いくつかのクラスタに横断するパラレルデータに関する棒グラフを描く. 例えば果物ごとというクラスタに横断する「輸入額」と「輸出額」など.
with boxes から with histogram へplot .. using <y>{:xtic(<xlabel>)}{:ytic(<ylabel>)} with histogram
<x> を与えないことに注意.
set style histogram clustered {gap <gapsize>}
cluster モードを有効にする. <gapsize> はクラスタ間の隙間の大きさを指定する (デフォルトは 2).
# <item>, <import-amount>, <export-amount>
$data <<EOD
apple 100 150
banana 200 180
candy 250 10
EOD
set style histogram clustered gap 1
set yrange [0:300]
set boxwidth 0.8 relative
set style fill solid 0.8 border lc rgb 'black'
# 塗りつぶしの色
set style line 1 lc rgb '#55aaff'
set style line 2 lc rgb '#ffaa55'
plot $data using 2:xtic(1) with histogram ls 1 title 'import amount' ,\
'' using 3 with histogram ls 2 title 'export amount'
Clustered histogram が横に並べるなら, 積み上げ棒グラフは縦に積み上げる.
rowstackedset style histogram rowstacked
積み上げ棒グラフモードを有効にする.
先の例
# <item>, <import-amount>, <export-amount>
$data <<EOD
apple 100 150
banana 200 180
candy 250 10
EOD
を行列と見たとき, 各行ごとに積み上げ棒グラフが描かれる.
関連するものに columnstacked があるが, ここでは扱わない.
$data <<EOD
apple 100 150
banana 200 180
candy 250 10
EOD
set style histogram rowstacked
set grid ytics
set yrange [0:]
set boxwidth 0.8 relative
set style fill solid 0.8 border lc rgb 'black'
# 塗りつぶしの色
set style line 1 lc rgb '#55aaff'
set style line 2 lc rgb '#ffaa55'
plot $data using 2:xtic(1) with histogram ls 1 title 'import amount' ,\
'' using 3 with histogram ls 2 title 'export amount'