COLOR(red){SIZE(20){グラフィックス参考実例集:matplot}}

([[グラフィックス参考実例集]]に戻る。[[Rのグラフィックスパラメータ]]を参照する。)~

matplot 関数は二つの行列の対応列毎の散布図を同時に描きます。列毎にプロットシンボルを変えることにより識別をしやすくします。いくつかのデータを重ねてプロットするためにplotとpointsを組み合わせて使うことができますが、座標系の設定などが煩わしくなります。
matplotは二つの 行列x、yをとり、その各列についてプロットをおこないます。座標系は全てのデータがうまく収まるように設定されます。列毎にマーカの色や形を変えて区別がつくようにもします。 引数type、lty、pch、colはtsplotと同じ様に指定することができます。 なお、上書き用にmatpoints、matlines が用意されています。 

#contents
~
** 例1。2種類のアヤメ(setosa, versicolor)の花弁・顎片の長さと幅の散布図の同時表示
** 例1。2種類のアヤメ(setosa, versicolor)の花弁・顎片の長さと幅の散布図の同時表示 [#af167967]
 matplot3 <- function() {
     data(iris)                  # is data.frame with  `Species' factor
     table(iris$Species)
     iS <- iris$Species == "setosa"
     iV <- iris$Species == "versicolor"
     op <- par(bg = "bisque")
     matplot(c(1, 8), c(0, 4.5), type= "n", xlab = "Length", ylab = "Width",
             main = "Petal and Sepal Dimensions in Iris Blossoms")
     matpoints(iris[iS,c(1,3)], iris[iS,c(2,4)], pch = "sS", col = c(2,4))
     matpoints(iris[iV,c(1,3)], iris[iV,c(2,4)], pch = "vV", col = c(2,4))
     legend(1, 4, c("    Setosa Petals", "    Setosa Sepals",
                    "Versicolor Petals", "Versicolor Sepals"),
            pch = "sSvV", col = rep(c(2,4), 2))
   }
#ref(matplot3.png,left)
#ref(グラフィックス参考実例集:matplot/matplot3.png,left)

**例2。 3種類のアヤメ(setosa, versicolor,virginica)の花弁の幅と長さの散布図の同時表示
**例2。 3種類のアヤメ(setosa, versicolor,virginica)の花弁の幅と長さの散布図の同時表示 [#m4adf372]

 matplot4 <- function() {
     data(iris)                  # is data.frame with  `Species' factor
     nam.var <- colnames(iris)[-5]
     nam.spec <- as.character(iris[1+50*0:2, "Species"])
     iris.S <- array(NA, dim = c(50,4,3), dimnames = list(NULL, nam.var, nam.spec))
     for(i in 1:3) iris.S[,,i] <- data.matrix(iris[1:50+50*(i-1), -5])
  
     matplot(iris.S[,"Petal.Length",], iris.S[,"Petal.Width",], pch="SCV",
             col = rainbow(3, start = .8, end = .1),
             sub = paste(c("S", "C", "V"), dimnames(iris.S)[[3]],
                         sep = "=", collapse= ",  "),
             main = "Fisher's Iris Data")
 }
#ref(matplot4.png, left)
#ref(グラフィックス参考実例集:matplot/matplot4.png, left)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS