08 November 2021

hands on PCA dengan R

file code saja

site mirror RPubs - hands on PCA dengan R

PCA R training

#instalasi

#instal R dari https://www.r-project.org/
#instal R Studio dari https://www.rstudio.com/

#library

#instal package dengan klik package/install/nama masing masing package di bawah
library(knitr) # untuk R markdown
library(ggplot2) #untuk fungsi grafik dengna ggplot
library(ggfortify) #untuk membuat pca dengan ggplot
library(cowplot) #untuk membuat grafik grid
library(rstatix ) #untuk fungsi uji normalitas shapiro wilk
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(ggpubr) #untuk membuat density plot uji normalitas
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:cowplot':
## 
##     get_legend

#PCA ##data

#data
data("iris")
iris
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1            5.1         3.5          1.4         0.2     setosa
## 2            4.9         3.0          1.4         0.2     setosa
## 3            4.7         3.2          1.3         0.2     setosa
## 4            4.6         3.1          1.5         0.2     setosa
## 5            5.0         3.6          1.4         0.2     setosa
## 6            5.4         3.9          1.7         0.4     setosa
## 7            4.6         3.4          1.4         0.3     setosa
## 8            5.0         3.4          1.5         0.2     setosa
## 9            4.4         2.9          1.4         0.2     setosa
## 10           4.9         3.1          1.5         0.1     setosa
## 11           5.4         3.7          1.5         0.2     setosa
## 12           4.8         3.4          1.6         0.2     setosa
## 13           4.8         3.0          1.4         0.1     setosa
## 14           4.3         3.0          1.1         0.1     setosa
## 15           5.8         4.0          1.2         0.2     setosa
## 16           5.7         4.4          1.5         0.4     setosa
## 17           5.4         3.9          1.3         0.4     setosa
## 18           5.1         3.5          1.4         0.3     setosa
## 19           5.7         3.8          1.7         0.3     setosa
## 20           5.1         3.8          1.5         0.3     setosa
## 21           5.4         3.4          1.7         0.2     setosa
## 22           5.1         3.7          1.5         0.4     setosa
## 23           4.6         3.6          1.0         0.2     setosa
## 24           5.1         3.3          1.7         0.5     setosa
## 25           4.8         3.4          1.9         0.2     setosa
## 26           5.0         3.0          1.6         0.2     setosa
## 27           5.0         3.4          1.6         0.4     setosa
## 28           5.2         3.5          1.5         0.2     setosa
## 29           5.2         3.4          1.4         0.2     setosa
## 30           4.7         3.2          1.6         0.2     setosa
## 31           4.8         3.1          1.6         0.2     setosa
## 32           5.4         3.4          1.5         0.4     setosa
## 33           5.2         4.1          1.5         0.1     setosa
## 34           5.5         4.2          1.4         0.2     setosa
## 35           4.9         3.1          1.5         0.2     setosa
## 36           5.0         3.2          1.2         0.2     setosa
## 37           5.5         3.5          1.3         0.2     setosa
## 38           4.9         3.6          1.4         0.1     setosa
## 39           4.4         3.0          1.3         0.2     setosa
## 40           5.1         3.4          1.5         0.2     setosa
## 41           5.0         3.5          1.3         0.3     setosa
## 42           4.5         2.3          1.3         0.3     setosa
## 43           4.4         3.2          1.3         0.2     setosa
## 44           5.0         3.5          1.6         0.6     setosa
## 45           5.1         3.8          1.9         0.4     setosa
## 46           4.8         3.0          1.4         0.3     setosa
## 47           5.1         3.8          1.6         0.2     setosa
## 48           4.6         3.2          1.4         0.2     setosa
## 49           5.3         3.7          1.5         0.2     setosa
## 50           5.0         3.3          1.4         0.2     setosa
## 51           7.0         3.2          4.7         1.4 versicolor
## 52           6.4         3.2          4.5         1.5 versicolor
## 53           6.9         3.1          4.9         1.5 versicolor
## 54           5.5         2.3          4.0         1.3 versicolor
## 55           6.5         2.8          4.6         1.5 versicolor
## 56           5.7         2.8          4.5         1.3 versicolor
## 57           6.3         3.3          4.7         1.6 versicolor
## 58           4.9         2.4          3.3         1.0 versicolor
## 59           6.6         2.9          4.6         1.3 versicolor
## 60           5.2         2.7          3.9         1.4 versicolor
## 61           5.0         2.0          3.5         1.0 versicolor
## 62           5.9         3.0          4.2         1.5 versicolor
## 63           6.0         2.2          4.0         1.0 versicolor
## 64           6.1         2.9          4.7         1.4 versicolor
## 65           5.6         2.9          3.6         1.3 versicolor
## 66           6.7         3.1          4.4         1.4 versicolor
## 67           5.6         3.0          4.5         1.5 versicolor
## 68           5.8         2.7          4.1         1.0 versicolor
## 69           6.2         2.2          4.5         1.5 versicolor
## 70           5.6         2.5          3.9         1.1 versicolor
## 71           5.9         3.2          4.8         1.8 versicolor
## 72           6.1         2.8          4.0         1.3 versicolor
## 73           6.3         2.5          4.9         1.5 versicolor
## 74           6.1         2.8          4.7         1.2 versicolor
## 75           6.4         2.9          4.3         1.3 versicolor
## 76           6.6         3.0          4.4         1.4 versicolor
## 77           6.8         2.8          4.8         1.4 versicolor
## 78           6.7         3.0          5.0         1.7 versicolor
## 79           6.0         2.9          4.5         1.5 versicolor
## 80           5.7         2.6          3.5         1.0 versicolor
## 81           5.5         2.4          3.8         1.1 versicolor
## 82           5.5         2.4          3.7         1.0 versicolor
## 83           5.8         2.7          3.9         1.2 versicolor
## 84           6.0         2.7          5.1         1.6 versicolor
## 85           5.4         3.0          4.5         1.5 versicolor
## 86           6.0         3.4          4.5         1.6 versicolor
## 87           6.7         3.1          4.7         1.5 versicolor
## 88           6.3         2.3          4.4         1.3 versicolor
## 89           5.6         3.0          4.1         1.3 versicolor
## 90           5.5         2.5          4.0         1.3 versicolor
## 91           5.5         2.6          4.4         1.2 versicolor
## 92           6.1         3.0          4.6         1.4 versicolor
## 93           5.8         2.6          4.0         1.2 versicolor
## 94           5.0         2.3          3.3         1.0 versicolor
## 95           5.6         2.7          4.2         1.3 versicolor
## 96           5.7         3.0          4.2         1.2 versicolor
## 97           5.7         2.9          4.2         1.3 versicolor
## 98           6.2         2.9          4.3         1.3 versicolor
## 99           5.1         2.5          3.0         1.1 versicolor
## 100          5.7         2.8          4.1         1.3 versicolor
## 101          6.3         3.3          6.0         2.5  virginica
## 102          5.8         2.7          5.1         1.9  virginica
## 103          7.1         3.0          5.9         2.1  virginica
## 104          6.3         2.9          5.6         1.8  virginica
## 105          6.5         3.0          5.8         2.2  virginica
## 106          7.6         3.0          6.6         2.1  virginica
## 107          4.9         2.5          4.5         1.7  virginica
## 108          7.3         2.9          6.3         1.8  virginica
## 109          6.7         2.5          5.8         1.8  virginica
## 110          7.2         3.6          6.1         2.5  virginica
## 111          6.5         3.2          5.1         2.0  virginica
## 112          6.4         2.7          5.3         1.9  virginica
## 113          6.8         3.0          5.5         2.1  virginica
## 114          5.7         2.5          5.0         2.0  virginica
## 115          5.8         2.8          5.1         2.4  virginica
## 116          6.4         3.2          5.3         2.3  virginica
## 117          6.5         3.0          5.5         1.8  virginica
## 118          7.7         3.8          6.7         2.2  virginica
## 119          7.7         2.6          6.9         2.3  virginica
## 120          6.0         2.2          5.0         1.5  virginica
## 121          6.9         3.2          5.7         2.3  virginica
## 122          5.6         2.8          4.9         2.0  virginica
## 123          7.7         2.8          6.7         2.0  virginica
## 124          6.3         2.7          4.9         1.8  virginica
## 125          6.7         3.3          5.7         2.1  virginica
## 126          7.2         3.2          6.0         1.8  virginica
## 127          6.2         2.8          4.8         1.8  virginica
## 128          6.1         3.0          4.9         1.8  virginica
## 129          6.4         2.8          5.6         2.1  virginica
## 130          7.2         3.0          5.8         1.6  virginica
## 131          7.4         2.8          6.1         1.9  virginica
## 132          7.9         3.8          6.4         2.0  virginica
## 133          6.4         2.8          5.6         2.2  virginica
## 134          6.3         2.8          5.1         1.5  virginica
## 135          6.1         2.6          5.6         1.4  virginica
## 136          7.7         3.0          6.1         2.3  virginica
## 137          6.3         3.4          5.6         2.4  virginica
## 138          6.4         3.1          5.5         1.8  virginica
## 139          6.0         3.0          4.8         1.8  virginica
## 140          6.9         3.1          5.4         2.1  virginica
## 141          6.7         3.1          5.6         2.4  virginica
## 142          6.9         3.1          5.1         2.3  virginica
## 143          5.8         2.7          5.1         1.9  virginica
## 144          6.8         3.2          5.9         2.3  virginica
## 145          6.7         3.3          5.7         2.5  virginica
## 146          6.7         3.0          5.2         2.3  virginica
## 147          6.3         2.5          5.0         1.9  virginica
## 148          6.5         3.0          5.2         2.0  virginica
## 149          6.2         3.4          5.4         2.3  virginica
## 150          5.9         3.0          5.1         1.8  virginica

##data export import

write.csv(iris,"iris.csv") #untuk export data dalam bentuk cvs
##ubah data cvs menjadi xlsx
### new document/data/get data/from cvs
#import data xlsx
##klik import dataset

data profile

iris %>% shapiro_test(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
## # A tibble: 4 x 3
##   variable     statistic        p
##   <chr>            <dbl>    <dbl>
## 1 Petal.Length     0.876 7.41e-10
## 2 Petal.Width      0.902 1.68e- 8
## 3 Sepal.Length     0.976 1.02e- 2
## 4 Sepal.Width      0.985 1.01e- 1
#  p-value > 0.05 implying that the distribution of the data are not significantly different from normal distribution. In other words, we can assume the normality.


g.density_Sepal.Length<-ggdensity(iris$Sepal.Length, 
          main = "Density plot of Sepal Length",
          xlab = "Sepal Length")

g.density_Sepal.Width<-ggdensity(iris$Sepal.Width, 
          main = "Density plot of Sepal Width",
          xlab = "Sepal Width")

g.density_Petal.Length<-ggdensity(iris$Petal.Length, 
          main = "Density plot of Petal Length",
          xlab = "Petal Length")

g.density_Petal.Width<-ggdensity(iris$Petal.Width, 
          main = "Density plot of Petal Width",
          xlab = "Petal Width")


g.density_iris_grid<-plot_grid(g.density_Petal.Length, g.density_Petal.Width, g.density_Sepal.Length, g.density_Sepal.Width,                       ncol=2,  align = 'v', rel_heights = c(1/5, 1/5, 1/5, 1/5),
                           labels = c('A', 'B', 'C', 'D'))
g.density_iris_grid

##data transformation ###log transformation

#https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/
#menggunakan log transformation, scaling and mean centering transformation
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]
log.ir
##     Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1       1.629241   1.2527630   0.33647224 -1.60943791
## 2       1.589235   1.0986123   0.33647224 -1.60943791
## 3       1.547563   1.1631508   0.26236426 -1.60943791
## 4       1.526056   1.1314021   0.40546511 -1.60943791
## 5       1.609438   1.2809338   0.33647224 -1.60943791
## 6       1.686399   1.3609766   0.53062825 -0.91629073
## 7       1.526056   1.2237754   0.33647224 -1.20397280
## 8       1.609438   1.2237754   0.40546511 -1.60943791
## 9       1.481605   1.0647107   0.33647224 -1.60943791
## 10      1.589235   1.1314021   0.40546511 -2.30258509
## 11      1.686399   1.3083328   0.40546511 -1.60943791
## 12      1.568616   1.2237754   0.47000363 -1.60943791
## 13      1.568616   1.0986123   0.33647224 -2.30258509
## 14      1.458615   1.0986123   0.09531018 -2.30258509
## 15      1.757858   1.3862944   0.18232156 -1.60943791
## 16      1.740466   1.4816045   0.40546511 -0.91629073
## 17      1.686399   1.3609766   0.26236426 -0.91629073
## 18      1.629241   1.2527630   0.33647224 -1.20397280
## 19      1.740466   1.3350011   0.53062825 -1.20397280
## 20      1.629241   1.3350011   0.40546511 -1.20397280
## 21      1.686399   1.2237754   0.53062825 -1.60943791
## 22      1.629241   1.3083328   0.40546511 -0.91629073
## 23      1.526056   1.2809338   0.00000000 -1.60943791
## 24      1.629241   1.1939225   0.53062825 -0.69314718
## 25      1.568616   1.2237754   0.64185389 -1.60943791
## 26      1.609438   1.0986123   0.47000363 -1.60943791
## 27      1.609438   1.2237754   0.47000363 -0.91629073
## 28      1.648659   1.2527630   0.40546511 -1.60943791
## 29      1.648659   1.2237754   0.33647224 -1.60943791
## 30      1.547563   1.1631508   0.47000363 -1.60943791
## 31      1.568616   1.1314021   0.47000363 -1.60943791
## 32      1.686399   1.2237754   0.40546511 -0.91629073
## 33      1.648659   1.4109870   0.40546511 -2.30258509
## 34      1.704748   1.4350845   0.33647224 -1.60943791
## 35      1.589235   1.1314021   0.40546511 -1.60943791
## 36      1.609438   1.1631508   0.18232156 -1.60943791
## 37      1.704748   1.2527630   0.26236426 -1.60943791
## 38      1.589235   1.2809338   0.33647224 -2.30258509
## 39      1.481605   1.0986123   0.26236426 -1.60943791
## 40      1.629241   1.2237754   0.40546511 -1.60943791
## 41      1.609438   1.2527630   0.26236426 -1.20397280
## 42      1.504077   0.8329091   0.26236426 -1.20397280
## 43      1.481605   1.1631508   0.26236426 -1.60943791
## 44      1.609438   1.2527630   0.47000363 -0.51082562
## 45      1.629241   1.3350011   0.64185389 -0.91629073
## 46      1.568616   1.0986123   0.33647224 -1.20397280
## 47      1.629241   1.3350011   0.47000363 -1.60943791
## 48      1.526056   1.1631508   0.33647224 -1.60943791
## 49      1.667707   1.3083328   0.40546511 -1.60943791
## 50      1.609438   1.1939225   0.33647224 -1.60943791
## 51      1.945910   1.1631508   1.54756251  0.33647224
## 52      1.856298   1.1631508   1.50407740  0.40546511
## 53      1.931521   1.1314021   1.58923521  0.40546511
## 54      1.704748   0.8329091   1.38629436  0.26236426
## 55      1.871802   1.0296194   1.52605630  0.40546511
## 56      1.740466   1.0296194   1.50407740  0.26236426
## 57      1.840550   1.1939225   1.54756251  0.47000363
## 58      1.589235   0.8754687   1.19392247  0.00000000
## 59      1.887070   1.0647107   1.52605630  0.26236426
## 60      1.648659   0.9932518   1.36097655  0.33647224
## 61      1.609438   0.6931472   1.25276297  0.00000000
## 62      1.774952   1.0986123   1.43508453  0.40546511
## 63      1.791759   0.7884574   1.38629436  0.00000000
## 64      1.808289   1.0647107   1.54756251  0.33647224
## 65      1.722767   1.0647107   1.28093385  0.26236426
## 66      1.902108   1.1314021   1.48160454  0.33647224
## 67      1.722767   1.0986123   1.50407740  0.40546511
## 68      1.757858   0.9932518   1.41098697  0.00000000
## 69      1.824549   0.7884574   1.50407740  0.40546511
## 70      1.722767   0.9162907   1.36097655  0.09531018
## 71      1.774952   1.1631508   1.56861592  0.58778666
## 72      1.808289   1.0296194   1.38629436  0.26236426
## 73      1.840550   0.9162907   1.58923521  0.40546511
## 74      1.808289   1.0296194   1.54756251  0.18232156
## 75      1.856298   1.0647107   1.45861502  0.26236426
## 76      1.887070   1.0986123   1.48160454  0.33647224
## 77      1.916923   1.0296194   1.56861592  0.33647224
## 78      1.902108   1.0986123   1.60943791  0.53062825
## 79      1.791759   1.0647107   1.50407740  0.40546511
## 80      1.740466   0.9555114   1.25276297  0.00000000
## 81      1.704748   0.8754687   1.33500107  0.09531018
## 82      1.704748   0.8754687   1.30833282  0.00000000
## 83      1.757858   0.9932518   1.36097655  0.18232156
## 84      1.791759   0.9932518   1.62924054  0.47000363
## 85      1.686399   1.0986123   1.50407740  0.40546511
## 86      1.791759   1.2237754   1.50407740  0.47000363
## 87      1.902108   1.1314021   1.54756251  0.40546511
## 88      1.840550   0.8329091   1.48160454  0.26236426
## 89      1.722767   1.0986123   1.41098697  0.26236426
## 90      1.704748   0.9162907   1.38629436  0.26236426
## 91      1.704748   0.9555114   1.48160454  0.18232156
## 92      1.808289   1.0986123   1.52605630  0.33647224
## 93      1.757858   0.9555114   1.38629436  0.18232156
## 94      1.609438   0.8329091   1.19392247  0.00000000
## 95      1.722767   0.9932518   1.43508453  0.26236426
## 96      1.740466   1.0986123   1.43508453  0.18232156
## 97      1.740466   1.0647107   1.43508453  0.26236426
## 98      1.824549   1.0647107   1.45861502  0.26236426
## 99      1.629241   0.9162907   1.09861229  0.09531018
## 100     1.740466   1.0296194   1.41098697  0.26236426
## 101     1.840550   1.1939225   1.79175947  0.91629073
## 102     1.757858   0.9932518   1.62924054  0.64185389
## 103     1.960095   1.0986123   1.77495235  0.74193734
## 104     1.840550   1.0647107   1.72276660  0.58778666
## 105     1.871802   1.0986123   1.75785792  0.78845736
## 106     2.028148   1.0986123   1.88706965  0.74193734
## 107     1.589235   0.9162907   1.50407740  0.53062825
## 108     1.987874   1.0647107   1.84054963  0.58778666
## 109     1.902108   0.9162907   1.75785792  0.58778666
## 110     1.974081   1.2809338   1.80828877  0.91629073
## 111     1.871802   1.1631508   1.62924054  0.69314718
## 112     1.856298   0.9932518   1.66770682  0.64185389
## 113     1.916923   1.0986123   1.70474809  0.74193734
## 114     1.740466   0.9162907   1.60943791  0.69314718
## 115     1.757858   1.0296194   1.62924054  0.87546874
## 116     1.856298   1.1631508   1.66770682  0.83290912
## 117     1.871802   1.0986123   1.70474809  0.58778666
## 118     2.041220   1.3350011   1.90210753  0.78845736
## 119     2.041220   0.9555114   1.93152141  0.83290912
## 120     1.791759   0.7884574   1.60943791  0.40546511
## 121     1.931521   1.1631508   1.74046617  0.83290912
## 122     1.722767   1.0296194   1.58923521  0.69314718
## 123     2.041220   1.0296194   1.90210753  0.69314718
## 124     1.840550   0.9932518   1.58923521  0.58778666
## 125     1.902108   1.1939225   1.74046617  0.74193734
## 126     1.974081   1.1631508   1.79175947  0.58778666
## 127     1.824549   1.0296194   1.56861592  0.58778666
## 128     1.808289   1.0986123   1.58923521  0.58778666
## 129     1.856298   1.0296194   1.72276660  0.74193734
## 130     1.974081   1.0986123   1.75785792  0.47000363
## 131     2.001480   1.0296194   1.80828877  0.64185389
## 132     2.066863   1.3350011   1.85629799  0.69314718
## 133     1.856298   1.0296194   1.72276660  0.78845736
## 134     1.840550   1.0296194   1.62924054  0.40546511
## 135     1.808289   0.9555114   1.72276660  0.33647224
## 136     2.041220   1.0986123   1.80828877  0.83290912
## 137     1.840550   1.2237754   1.72276660  0.87546874
## 138     1.856298   1.1314021   1.70474809  0.58778666
## 139     1.791759   1.0986123   1.56861592  0.58778666
## 140     1.931521   1.1314021   1.68639895  0.74193734
## 141     1.902108   1.1314021   1.72276660  0.87546874
## 142     1.931521   1.1314021   1.62924054  0.83290912
## 143     1.757858   0.9932518   1.62924054  0.64185389
## 144     1.916923   1.1631508   1.77495235  0.83290912
## 145     1.902108   1.1939225   1.74046617  0.91629073
## 146     1.902108   1.0986123   1.64865863  0.83290912
## 147     1.840550   0.9162907   1.60943791  0.64185389
## 148     1.871802   1.0986123   1.64865863  0.69314718
## 149     1.824549   1.2237754   1.68639895  0.83290912
## 150     1.774952   1.0986123   1.62924054  0.58778666
iris_log<-cbind(log.ir,ir.species)

log.ir %>% shapiro_test(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
## # A tibble: 4 x 3
##   variable     statistic        p
##   <chr>            <dbl>    <dbl>
## 1 Petal.Length     0.817 2.04e-12
## 2 Petal.Width      0.821 3.05e-12
## 3 Sepal.Length     0.983 5.39e- 2
## 4 Sepal.Width      0.989 3.01e- 1

scaling and mean centering

iris_data<-iris[,1:4]
iris_center_scale_data<-as.data.frame(scale(iris_data, center = TRUE, scale = TRUE))
iris_center_scale<-cbind(iris_center_scale_data, ir.species)
iris_log_center_scale_data<-as.data.frame(scale(log.ir, center = TRUE, scale = TRUE))
iris_log_center_scale<-cbind(iris_log_center_scale_data, ir.species)

##boxspot comparison with ggplot

g.boxplot_iris<-iris %>% dplyr::select(Species, everything()) %>% tidyr::gather("id", "value",2:5) %>% 
  ggplot(., aes(x = id, y = value))+geom_boxplot()

g.boxplot_iris_log<-iris_log %>% dplyr::select(ir.species, everything()) %>% tidyr::gather("id", "value",2:5) %>% 
  ggplot(., aes(x = id, y = value))+geom_boxplot()

g.boxplot_iris_center_scale<-iris_center_scale %>% dplyr::select(ir.species, everything()) %>% tidyr::gather("id", "value",2:5) %>% 
  ggplot(., aes(x = id, y = value))+geom_boxplot()

g.boxplot_iris_log_center_scale<-iris_log_center_scale %>% dplyr::select(ir.species, everything()) %>% tidyr::gather("id", "value",2:5) %>% 
  ggplot(., aes(x = id, y = value))+geom_boxplot()

g.boxplot_iris_comparison<-plot_grid(g.boxplot_iris, g.boxplot_iris_log, g.boxplot_iris_center_scale, g.boxplot_iris_log_center_scale, ncol=2,  align = 'v', rel_heights = c(1/5, 1/5, 1/5, 1/5),
                           labels = c('A', 'B', 'C', 'D'))
g.boxplot_iris_comparison

# A. g.boxplot_iris, 
# B. g.boxplot_iris_log,
# C. g.boxplot_iris_center_scale,
# D. g.boxplot_iris_log_center_scale

##PCA dengan ggplot profil lengkap

g.pca_iris_compl<-autoplot(prcomp(iris_data), data = iris, colour = 'Species', frame = T, loadings = TRUE, loadings.label = TRUE)
g.pca_iris_compl

g.scree_iris<-plot(prcomp(iris_data))

g.scree_iris
## NULL

##PCA dengan ggplot perbandingan

g.pca_iris<-autoplot(prcomp(iris_data), data = iris, colour = 'Species', frame = T)
g.pca_iris_log<-autoplot(prcomp(log.ir), data = iris_log, colour = 'ir.species', frame = T)
g.pca_iris_center_scale<-autoplot(prcomp(iris_center_scale_data, center =  FALSE), data = iris_center_scale, colour = 'ir.species', frame = T)
g.pca_iris_log_center_scale<-autoplot(prcomp(iris_log_center_scale_data, center =  FALSE), data = iris_log_center_scale, colour = 'ir.species', frame = T)

g.pca_iris_comparison<-plot_grid(g.pca_iris, g.pca_iris_log, g.pca_iris_center_scale, g.pca_iris_log_center_scale, ncol=2,  align = 'v', rel_heights = c(1/5, 1/5, 1/5, 1/5),
                           labels = c('A', 'B', 'C', 'D'))
g.pca_iris_comparison

# A. g.pca_iris, 
# B. g.pca_iris_log,
# C. g.pca_iris_center_scale,
# D. g.pca_iris_log_center_scale
ggsave("g.pca_iris_comparison.pdf", g.pca_iris_comparison, width = 200, height = 110, units = "mm",
       dpi = 600, limitsize = TRUE)#untuk cetak ke dalam pdf

ggsave("g.pca_iris_comparison.jpg", g.pca_iris_comparison, width = 200, height = 110, units = "mm",
       dpi = 600, limitsize = TRUE)#untuk cetak ke dalam jpg