はじめに
SAS には多種多様なグラフの描き方が存在します。ここでは Proc gplot を使用したグラフの描き方を紹介します。コード例とその下にコード説明をしております。最後にコード全体を記載していますので、ご確認ください。 以下のデータをプロットする方法をご紹介します。date | hajimari | owarine |
---|---|---|
01/13/2017 | 113.758 | 114.027 |
01/14/2017 | 114.026 | 113.771 |
01/15/2017 | 113.77 | 113.983 |
01/16/2017 | 113.983 | 115.241 |
01/17/2017 | 115.285 | 115.021 |
01/18/2017 | 115.022 | 115.166 |
01/19/2017 | 115.166 | 117.144 |
データ読み込み
1 |
proc gplot data = work.test; |
タイトルの設定
1 2 |
title1 "maintitle"; title2 "subtitile"; |
軸の設定
1 2 |
axis1 order = (110 to 118 by .01); axis2 order = ("01Feb2017"d to "15Mar2017"d by day); |
order = (110 to 118 by .01)
で 110~118 の範囲の値を 0.01 刻みで表示、order = (“01Feb2017”d to “15Mar2017”d by day)
で 2017/02/01~2017/03/15 の範囲を 1 日刻みで表示します。
グラフ線の形状を指定
1 |
symbol1 I = join V = dot C = blue |
I = join
は点と点を線で結びます。V = dot
で丸い形状を指定します。C = blue
で青い点の色を指定します。
グラフを描く
1 |
plot hajimari*date / vaxis=axis1 haxis=axis2 |
1 2 3 4 5 6 7 8 |
proc gplot data = work.test; title1 “maintitle”; title2 “subtitile”; axis1 order = (110 to 118 by .01); axis2 order = ("01Feb2017"d to "15Mar2017"d by day); symbol1 I = join V = dot C = blue; plot hajimari*date / vaxis=axis1 haxis=axis2; run; |

グラフ背景色変更
ここからグラフの調整をさらに加えていきます。
1 |
plot hajimari*date / vaxis=axis1 haxis=axis2 regeqn cframe=grayee |

グラフ縦軸参照線
1 |
plot hajimari*date / vaxis=axis1 haxis=axis2 vref = 111 113 115 cvref=black green red lvref=10 3 1 |

グラフ横軸参照線
1 |
plot hajimari*date/ vaxis=axis1 haxis=axis2 href = "1Mar2017"d chref=black lhref=10 |

グラフの重ね書き
1 2 3 4 |
symbol1 I = join V = dot C = blue plot hajimari*date/overlay vaxis= axis1 haxis=axis2 symbol2 I = none V = dot C = red plot2 owarine*date |

凡例の表示
1 2 3 4 5 |
legend1 Frame symbol1 I = join V = dot C = blue plot hajimari*date/overlay vaxis= axis1 haxis=axis2 legend=legend1 symbol2 I = none V = dot C = red legend=legend2 plot2 owarine*date |
