setwd("/home/duncan/Dropbox/Public/Analyses/matan")
a<-dir()
d<-read.csv(a[1])
d2<-read.csv(a[2])
library(reshape)
d1<-data.frame(id=1:186,d)
d1<-melt(d1,id=1)
library(ggplot2)
str(d1)
## 'data.frame': 3162 obs. of 3 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ variable: Factor w/ 17 levels "Mg","Si","K",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ value : num 3141 1130 0 2361 1401 ...
g0<-ggplot(d1,aes(x=value))
g1<-g0 + geom_histogram(fill="grey",colour="black") + theme_bw()
g1+facet_wrap(~variable)
g0<-ggplot(d1,aes(x=log10(value)))
g1<-g0 + geom_histogram(fill="grey",colour="black") + theme_bw()
g1+facet_wrap(~variable)
g0<-ggplot(d1,aes(sample=log10(value)))
g1<-g0 + stat_qq() + theme_bw()
g1+facet_wrap(~variable)
library(GGally)
f<-function(x)log10(x+0.1)
d2<-f(d)
ggpairs(d2[,1:8])
ggpairs(d2[,9:17])
So some problems with the zeros. We can still use PCA
pca<-prcomp(d2,scale=TRUE,center=TRUE,retx=TRUE)
plot(pca)
biplot(pca)
pca
## Standard deviations:
## [1] 2.5617 1.7606 1.3459 0.9725 0.9174 0.8688 0.7874 0.6981 0.6717 0.5763
## [11] 0.5440 0.5270 0.4086 0.3675 0.3200 0.2651 0.2126
##
## Rotation:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Mg -0.10902 0.39868 -0.03883 0.198026 -0.121227 0.50623 -0.42902
## Si -0.32056 0.22056 0.11034 0.058839 -0.139682 0.16548 0.02300
## K 0.07580 0.39811 0.26051 0.009638 0.101057 0.03472 0.28176
## Ca -0.26913 0.02609 -0.45587 -0.152006 0.052248 0.16873 0.02297
## P 0.13706 0.35216 0.16802 0.339847 0.331035 -0.14698 0.17924
## Fe -0.36454 -0.04480 0.11134 -0.017452 -0.100942 -0.17822 0.09934
## Ti -0.36002 -0.03413 0.16952 0.024166 -0.181312 -0.01580 0.14380
## Mn -0.28004 -0.05267 -0.09905 0.509381 0.095089 0.13358 -0.10929
## Al -0.31889 0.15965 -0.06175 -0.227934 -0.236034 0.15610 0.27242
## Sr -0.16792 0.06104 -0.46818 -0.078047 0.565975 0.10908 0.16932
## S 0.01812 0.37556 -0.31120 0.160440 -0.409367 -0.32564 -0.07414
## Cl 0.07646 0.38410 -0.31746 0.022835 -0.061607 -0.42985 0.16508
## V -0.30339 0.10946 0.19456 -0.419078 0.052643 -0.09757 0.16099
## Cr -0.27230 -0.03207 0.10116 -0.039922 0.006731 -0.44515 -0.53435
## Zn -0.09342 0.33976 0.25228 -0.277453 0.430573 -0.05863 -0.36920
## Zr -0.26572 -0.08927 0.25226 0.442813 0.108200 -0.07485 0.26533
## Ba -0.25667 -0.22151 -0.18830 0.153885 0.209349 -0.26723 -0.08425
## PC8 PC9 PC10 PC11 PC12 PC13 PC14
## Mg 0.03363 -0.01302 -0.047001 0.3584678 -0.024633 0.33272 0.28227
## Si -0.04361 -0.19707 -0.020542 0.1102417 0.103583 -0.10990 -0.74198
## K 0.71863 0.17754 -0.002162 0.0664442 0.130382 -0.30262 0.11926
## Ca -0.10677 -0.02310 0.181907 -0.0152396 -0.137041 -0.53669 0.36062
## P -0.19794 -0.46288 0.454656 -0.0999960 -0.204357 0.07943 0.09059
## Fe 0.05062 0.00157 -0.015992 -0.0561773 0.009588 0.07103 0.04362
## Ti -0.04814 0.03748 -0.058978 0.0545765 0.001466 -0.05425 0.10198
## Mn 0.19280 0.21437 -0.136957 -0.5412576 -0.421147 -0.01630 -0.11048
## Al -0.08795 -0.17232 0.242437 0.0036855 -0.082615 -0.08286 -0.01660
## Sr 0.11202 -0.20500 -0.255564 -0.0781447 0.394072 0.23281 -0.08596
## S -0.06127 0.20755 0.207191 -0.3500172 0.471053 0.11513 0.04409
## Cl -0.10376 0.08216 -0.444263 0.3306388 -0.442530 -0.01383 -0.08331
## V 0.04767 0.09789 -0.005585 -0.1935435 -0.201403 0.54638 0.19159
## Cr 0.25442 -0.49872 -0.150308 -0.0003119 0.061850 -0.15778 0.14448
## Zn -0.35031 0.41191 0.024918 -0.1056246 0.046923 -0.23134 -0.11508
## Zr -0.34779 0.11615 -0.261737 0.1981394 0.325342 -0.08687 0.28695
## Ba 0.20598 0.32297 0.528141 0.4688048 -0.037202 0.15506 -0.15195
## PC15 PC16 PC17
## Mg -0.065060 0.06381 -0.04613
## Si -0.028290 -0.36457 -0.15863
## K 0.030940 -0.01951 -0.02216
## Ca -0.127344 -0.35982 -0.19088
## P -0.147204 -0.03403 0.03013
## Fe -0.535476 0.44048 -0.55390
## Ti -0.462932 -0.04853 0.73886
## Mn 0.137921 0.06622 0.05102
## Al 0.505208 0.52814 0.13570
## Sr -0.073599 0.12651 0.13268
## S 0.012500 -0.08019 0.03121
## Cl 0.005413 0.04463 0.01752
## V 0.159940 -0.42932 -0.09613
## Cr 0.198765 -0.01779 0.06169
## Zn -0.013952 0.18012 0.06559
## Zr 0.321287 -0.10330 -0.14884
## Ba 0.081942 -0.01178 0.05250
So two quite orthoganal axes, the first capturing silicon, barium etc and the second magnesium zinc etc (see rotated loadings). This is useful for further analysis.