【R】loon.tour

1. はじめに

loon.tourは、インタラクティブなプロットを提供するloonの拡張パッケージです。

2. インストール

CRANからインストールできます。

install.packages("loon.tourr")

3. つかってみる

相関図を描いてみます。

oliveというデータセットを使います。

head(olive)
> head(olive)
  region          area palmitic palmitoleic stearic oleic linoleic linolenic arachidic eicosenoic
1      1 North-Apulia      1075          75     226  7823      672        36        60         29
2      1 North-Apulia      1088          73     224  7709      781        31        61         29
3      1 North-Apulia       911          54     246  8113      549        31        63         29
4      1 North-Apulia       966          57     240  7952      619        50        78         35
5      1 North-Apulia      1051          67     259  7771      672        50        80         46
6      1 North-Apulia       911          49     268  7924      678        51        70         44
library(loon.tourr)

q <- l_tour_pairs(olive[, -c(1:2)],
                  color = olive$region)
proj <- q["projection"]
lc <- l_getPlots(q)
layer_pack <- lapply(lc, function(w) l_layer_density2d(w))
q <- l_tour_pairs(tourr::flea[, 1:6],
                  as.l_tour = FALSE,
                  color = tourr::flea$species,
                  showHistogram = TRUE,
                  showSerialAxes = TRUE)
proj <- l_getProjection(q, tourr::flea[, 1:6])
proj
> proj
$x2y2
             [,1]         [,2]
[1,]  0.002964348  0.986519561
[2,]  0.986340794 -0.003766611
[3,] -0.115387925 -0.114623708
[4,] -0.008368167 -0.008312744
[5,] -0.117095910 -0.116320381
[6,]  0.005215342  0.005180801

$x3y2
             [,1]         [,2]
[1,]  0.003358595  0.986519561
[2,] -0.004296008 -0.003766611
[3,]  0.991082404 -0.114623708
[4,] -0.009481102 -0.008312744
[5,] -0.132669235 -0.116320381
[6,]  0.005908964  0.005180801

$x4y2
             [,1]         [,2]
[1,]  0.002977872  0.986519561
[2,] -0.003809022 -0.003766611
[3,] -0.115914361 -0.114623708
[4,]  0.986243472 -0.008312744
[5,] -0.117630139 -0.116320381
[6,]  0.005239136  0.005180801

$x3y3
             [,1]         [,2]
[1,]  0.003358595  0.002964348
[2,] -0.004296008  0.986340794
[3,]  0.991082404 -0.115387925
[4,] -0.009481102 -0.008368167
[5,] -0.132669235 -0.117095910
[6,]  0.005908964  0.005215342

$x4y3
             [,1]         [,2]
[1,]  0.002977872  0.002964348
[2,] -0.003809022  0.986340794
[3,] -0.115914361 -0.115387925
[4,]  0.986243472 -0.008368167
[5,] -0.117630139 -0.117095910
[6,]  0.005239136  0.005215342

$x4y4
             [,1]         [,2]
[1,]  0.002977872  0.003358595
[2,] -0.003809022 -0.004296008
[3,] -0.115914361  0.991082404
[4,]  0.986243472 -0.009481102
[5,] -0.117630139 -0.132669235
[6,]  0.005239136  0.005908964

$x2y1
             [,1]
[1,]  0.002964348
[2,]  0.986340794
[3,] -0.115387925
[4,] -0.008368167
[5,] -0.117095910
[6,]  0.005215342

$x3y1
             [,1]
[1,]  0.003358595
[2,] -0.004296008
[3,]  0.991082404
[4,] -0.009481102
[5,] -0.132669235
[6,]  0.005908964

$x4y1
             [,1]
[1,]  0.002977872
[2,] -0.003809022
[3,] -0.115914361
[4,]  0.986243472
[5,] -0.117630139
[6,]  0.005239136

$x5y2
             [,1]
[1,]  0.986519561
[2,] -0.003766611
[3,] -0.114623708
[4,] -0.008312744
[5,] -0.116320381
[6,]  0.005180801

$x5y3
             [,1]
[1,]  0.002964348
[2,]  0.986340794
[3,] -0.115387925
[4,] -0.008368167
[5,] -0.117095910
[6,]  0.005215342

$x5y4
             [,1]
[1,]  0.003358595
[2,] -0.004296008
[3,]  0.991082404
[4,] -0.009481102
[5,] -0.132669235
[6,]  0.005908964

$serialAxes
               V1           V2           V3           V4
[1,]  0.986519561  0.002964348  0.003358595  0.002977872
[2,] -0.003766611  0.986340794 -0.004296008 -0.003809022
[3,] -0.114623708 -0.115387925  0.991082404 -0.115914361
[4,] -0.008312744 -0.008368167 -0.009481102  0.986243472
[5,] -0.116320381 -0.117095910 -0.132669235 -0.117630139
[6,]  0.005180801  0.005215342  0.005908964  0.005239136

インタラクティブなプロットが表示されます。

density plot も描けます。

p <- l_plot(iris, color = iris$Species)
l <- l_layer_density2d(p)

4. さいごに

インタラクティブなプロットがかけるloonの可能性がさらに広がります。

Add a Comment

メールアドレスが公開されることはありません。