lattice包提供了很多畫圖函數,這兒我們使用lattice包splom()畫散點矩陣圖和parallelplot()畫平行座標圖;
記得有一次幫別人畫基因cluster隨時間表達模式圖;每個基因在各個時刻表達值使用一條折線表示,當時使用了循環一條線一條線的畫;現在可以使用parallelplot()這個函數;
Draw Conditional Scatter Plot Matrices and Parallel Coordinate Plots
Usage
splom(x, data, ...)
parallelplot(x, data, ...)
x: 可以是表達式,也可以是data.frame;
表達式格式:~ x | g1 * g2 ;x可以是數據框或者矩陣;g1,g2是數據因子;展示g1 * g2 各水平組合下,x中各數據分佈情況;
group: 選擇分組的因子
library(lattice)
super.sym <- trellis.par.get("superpose.symbol")
splom(~iris[1:4], groups = Species, data = iris,
panel = panel.superpose,
key = list(title = "Three Varieties of Iris",
columns = 3,
points = list(pch = super.sym$pch[1:3],
col = super.sym$col[1:3]),
text = list(c("Setosa", "Versicolor", "Virginica"))))
splom(~iris[1:3]|Species, data = iris,
layout=c(2,2), pscales = 0,
varnames = c("Sepal\nLength", "Sepal\nWidth", "Petal\nLength"),
page = function(...) {
ltext(x = seq(.6, .8, length.out = 4),
y = seq(.9, .6, length.out = 4),
labels = c("Three", "Varieties", "of", "Iris"),
cex = 2)
})
parallelplot(~iris[1:4] | Species, iris)
parallelplot(~iris[1:4], iris, groups = Species,
horizontal.axis = FALSE, scales = list(x = list(rot = 90)))