LoginSignup
5
3

More than 5 years have passed since last update.

ggplotで平行座標、散布図行列を描く

Last updated at Posted at 2018-02-15

はじめに

データの可視化について
* 平行座標プロット
* 散布図行列

が便利だよ、ということなので使ってみる。

平衡座標プロット

キモはID列をつくって、groupで行ごとにプロットさせることらしい。
また、必要に応じて変数を正規化する。

parallel_plot.r
library("tidyverse")

ggplot(iris %>% 
         sample_n(15) %>% #数が多いので一部のみ抽出
         mutate(ID = 1:n()) %>% #ID割り振り
         mutate_if(is.numeric,scale) %>%  #正規化
        gather(key,value,c(1,1:4)), #long styleに変換
        aes(key,value,group=ID,colour=Species))+ 
    geom_line() +
    geom_point(size=2,shape=1) #軸との交点を見やすくするオプション

parallel.jpeg

散布図行列

GGallayを使って一発

scatter_plot_matrix.r
library("ggplot2")
library("GGally")

ggpairs(iris,aes_string(colour="Species")

sanpu.jpeg

参考サイト

統計はデータと人間のインターフェース ~統計数理研究所 中野純司先生インタビュー〜
How to plot parallel coordinates with multiple categorical variables in R
【Rメモ】多変数の関係性を視覚化する関数(パッケージ)まとめ

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3