多變量資料繪圖

R 的多變量機率分配

Surajit Ray

Professor, University of Glasgow

各種繪圖選項

 

  • 基本 R 繪圖
  • lattice 函式庫
  • ggplot
  • 3D 繪圖選項
R 的多變量機率分配

多變量的基本 R 繪圖

pairs(iris_raw[, 1:4])

pairs plot

  • 變數多時,圖不易解讀
R 的多變量機率分配

以顏色區分類別的 pairs 圖

pairs(iris_raw[, 1:4], col = iris_raw$Species)

pairs plot by species

R 的多變量機率分配

Lattice

library(lattice)
splom(~iris_raw[, 1:4], col = iris_raw$Species, pch = 16)

R 的多變量機率分配

使用 ggplot

library(ggplot2)
library(GGally)
ggpairs(data = iris_raw, columns = 1:4, mapping = aes(color = Species))

ggplot

R 的多變量機率分配

3D 繪圖

library(scatterplot3d)
scatterplot3d(iris_raw[, c(1, 3, 4)], color = as.numeric(iris_raw$Species))

3d

R 的多變量機率分配

3D 繪圖

scatterplot3d(iris_raw[, c(1, 3, 4)], color = as.numeric(iris_raw$Species),pch = 4, angle = 80)

3dchange

R 的多變量機率分配

用葡萄酒資料來練習繪圖吧!

R 的多變量機率分配

Preparing Video For Download...