相関とれるっぽい行列を作成
> cb<-cbind(
c(10,20,30,40,50,60,70,80,90),
c(90,80,70,60,10,40,30,20,10),
c(20,20,30,30,70,60,70,70,70),
c(20,20,30,30,20,60,70,70,70),
c(50,80,90,30,50,80,90,10,30),
c(30,10,40,30,60,70,20,10,40),
c(30,30,40,40,10,50,60,60,70)
)
> cb
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 2 3 3
[3,] 3 3 4
[4,] 4 5 4
[5,] 5 6 5
[6,] 6 7 5
[7,] 7 7 6
プロットする
matplot(cb, type="o", xlab="taste level", ylab="head-count", pch=c(1,2,3,4,5,6,10))
オプションについて少しメモっておく。
pch - プロット記号本当は18種類あるらしい。
(1- ◯, 2- △, 3- +, 4- ☓, 5- ♢, 6- △, 7- □, 8- *, 9- ◇)
type - グラフの種類what type of plot should be drawn. Possible types are
"p" for points,
"l" for lines,
"b" for both,
"c" for the lines part alone of "b",
"o" for both ‘overplotted’,
"h" for ‘histogram’ like (or ‘high-density’) vertical lines,
"s" for stair steps,
"S" for other steps, see ‘Details’ below,
"n" for no plotting.
xlab: "x軸ラベル名"
ylab: "y軸ラベル名"
ついでにラベルもつけてみる
ラベルの座標はlocator(1)を使うと表示後にクリックした場所に表示されるので便利。
legend(
locator(1),
legend=c("AB","AC","AD","AE","AF","AG","AH"), # ラベルの名前
col=c("black","blue","green", "red","green3", "darkorchid1","cyan3","aquamarine3"),
lty=c(1:7), # 線の種類
pch=c(1,2,3,4,5,6,10), # ポイントの種類
bg='gray90' # 背景色
)
相関係数行列を作ってみる。
> cor(cb)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1.00000000 -0.8991013 0.9067964 0.89527379 -0.3703280 0.08827348 0.7319251
[2,] -0.89910135 1.0000000 -0.9649709 -0.64162033 0.3699583 -0.28219309 -0.3655971
[3,] 0.90679645 -0.9649709 1.0000000 0.74430638 -0.2433421 0.27262071 0.4424714
[4,] 0.89527379 -0.6416203 0.7443064 1.00000000 -0.1801875 -0.06013071 0.9116846
[5,] -0.37032804 0.3699583 -0.2433421 -0.18018749 1.0000000 0.19069252 -0.1807016
[6,] 0.08827348 -0.2821931 0.2726207 -0.06013071 0.1906925 1.00000000 -0.2369018
[7,] 0.73192505 -0.3655971 0.4424714 0.91168461 -0.1807016 -0.23690177 1.0000000