Main Content

グループ化されたデータを使用した散布図の作成

この例では、グループ化された標本データを使用して散布図を作成する方法を示します。

散布図とは、1 つの変数対別の変数の簡単なプロットです。MATLAB® の関数 plot および scatter は散布図を作成します。MATLAB 関数 plotmatrix は、複数の変数ペアの関係を示すようなプロットの行列を作成できます。

Statistics and Machine Learning Toolbox™ の関数 gscatter および gplotmatrix は、これらをグループ化してプロットします。これらの関数は、2 つの変数の値またはこれらの変数の関係が各グループ内で同じかどうかを判定するのに役立ちます。これらの関数では、異なるプロット シンボルを使用してグループのメンバーシップを示します。gname を使用すると、テキスト ラベルまたは観測番号によってプロット上の点にラベルを付けることができます。

3 つの異なる年のモデルから自動車の重量と燃費を調べたいと仮定します。

load carsmall
gscatter(Weight,MPG,Model_Year,'bgr','xos')

Figure contains an axes object. The axes object with xlabel Weight, ylabel MPG contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent 70, 76, 82.

これは、自動車の重量と燃費の間に強い関係あることだけでなく、新しい自動車は軽く、古い自動車よりも燃費が良い傾向にあることを示します。

gscatter の既定の設定の引数は、同じ記号で色が異なるものを使って異なるグループをもつ散布図を生成します。上記の最後の 2 つの引数は、すべてのグループが既定の設定の色で、異なる記号を使って表示されることを要求します。

データ セット carsmall は、自動車のその他の側面を記述するそれ以外の変数を含みます。グループ化されたプロット行列を作成することにより、1 つの表示内で複数の変数を調べることができます。

xvars = [Weight Displacement Horsepower];
yvars = [MPG Acceleration];
gplotmatrix(xvars,yvars,Model_Year,'bgr','xos')

Figure contains 6 axes objects. Axes object 1 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 2 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 3 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 4 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 5 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 6 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent 70, 76, 82.

右上のサブプロットは、Horsepower に対する MPG を表示し、年が経つごとに自動車の馬力が減少し、燃費が改善されていることを示します。

関数 gplotmatrix は、各変数のヒストグラムと共に、変数のリストからすべてのペアをグラフ化することができます。多変量分散分析 (MANOVA) の実行を参照してください。

参考

| |

関連するトピック