階層クラスタリング:職業クラスターのプロット
階層クラスタリングの結果を分析するために必要な要素がすべて揃いました。この演習では、名前付き代入ベクター cut_oes と整然データフレーム gathered_oes を活用して、クラスタリングの結果を分析しましょう。
この演習はコースの一部です
Rによるクラスター分析
演習の手順
sort()を使ってcut_oesベクターを並び替え、各職業のクラスター割り当てを確認しましょう。- ggplot2 を使って、各職業の年ごとの平均賃金をプロットし、職業ごとに割り当てられたクラスターで線の色を分けましょう。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# View the clustering assignments by sorting the cluster assignment vector
sort(___)
# Plot the relationship between mean_salary and year and color the lines by the assigned cluster
ggplot(___, aes(x = ___, y = ___, color = factor(___))) +
geom_line(aes(group = occupation))