library(ggplot2)
library(ggExtra)
library(tidyverse)
[30m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.2.1 --[39m
[30m[32mv[30m [34mtibble [30m 1.4.2 [32mv[30m [34mpurrr [30m 0.2.5
[32mv[30m [34mtidyr [30m 0.8.1 [32mv[30m [34mdplyr [30m 0.7.6
[32mv[30m [34mreadr [30m 1.1.1 [32mv[30m [34mstringr[30m 1.3.1
[32mv[30m [34mtibble [30m 1.4.2 [32mv[30m [34mforcats[30m 0.3.0[39m
[30m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[30m [34mdplyr[30m::[32mfilter()[30m masks [34mstats[30m::filter()
[31mx[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()[39m
library(psych)
Attaching package: 㤼㸱psych㤼㸲
The following objects are masked from 㤼㸱package:ggplot2㤼㸲:
%+%, alpha
library(ggcorrplot)
library(stats)
library(FactoMineR)
library(ggmap)
Google Maps API Terms of Service: http://developers.google.com/maps/terms.
Please cite ggmap if you use it: see citation("ggmap") for details.
library(rgdal)
rgdal: version: 1.3-3, (SVN revision 759)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/leona/AppData/Local/conda/conda/envs/rstudio/lib/R/library/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/leona/AppData/Local/conda/conda/envs/rstudio/lib/R/library/rgdal/proj
Linking to sp version: 1.3-1
Geral <- read.csv("Geral.csv", as.is=TRUE, sep=",") %>% as.data.frame()
Geral <- Geral[-c(57, 67, 68, 69),]
describe(Geral)
NAs introduced by coercionno non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf
Elements <- c(5, 7, 8, 10, 11, 12, 14, 15, 16, 20, 23, 25, 27)
Chemical_Tr <- select(Geral, c(Elements))
Mag_Param <- c("SusF1","ARM","SIRM_VSM","MU","MS")
Tracers <- select(Geral, c(Elements, Mag_Param)) %>% na.omit()
describe(Tracers)
Species subset is a agreggate of the tracers with the tree species to use multi-type multivariate statistics
Species <- select(Geral, c("Especie", Elements, Mag_Param)) %>% as.data.frame %>% na.omit()
Species$Especie <- as.factor(Species$Especie)
str(Species)
'data.frame': 63 obs. of 19 variables:
$ Especie : Factor w/ 2 levels "Sibipiruna","Tipuana": 2 2 2 2 2 2 2 2 1 1 ...
$ Al : num 148 1957 278 324 908 ...
$ Ba : num 132 1053 166 604 646 ...
$ Ca : num 3.85 1.73 3.13 3.71 3.24 ...
$ Cl : num 197 275 249 131 358 ...
$ Cu : num 6.38 11.52 6.36 7.58 8.27 ...
$ Fe : num 231 2788 648 642 1898 ...
$ K : num 605 1162 962 805 1172 ...
$ Mg : num 2308 610 2255 975 1788 ...
$ Mn : num 44.8 49.6 51.2 240 132.3 ...
$ P : num 718 542 802 802 968 ...
$ S : num 3252 2478 2590 2565 2992 ...
$ Sr : num 150.8 79.5 114 178.7 157.8 ...
$ Zn : num 124 258 166 408 239 ...
$ SusF1 : num 2.28e-06 4.60e-05 9.08e-06 1.02e-05 3.43e-05 ...
$ ARM : num -5.80e-08 7.01e-06 2.17e-05 1.26e-04 4.01e-06 ...
$ SIRM_VSM: num 6.20e-07 3.81e-06 1.24e-06 1.14e-06 3.31e-06 ...
$ MU : num 7.84e-19 9.07e-19 8.28e-19 4.93e-19 4.20e-19 ...
$ MS : num 4.40e-06 4.67e-05 1.06e-05 1.28e-05 4.22e-05 ...
- attr(*, "na.action")= 'omit' Named int 2 57
..- attr(*, "names")= chr "2" "58"
Map subset is a agg. of the spacial data
Map <- select(Geral, c("Lat", "Long", "Latcart", "Longcart", Elements, Mag_Param)) %>% na.omit()
describe(Map)
corr <- cor(Tracers, use = "complete.obs") %>% round(1)
ggcorrplot(corr, hc.order = TRUE,
type = "lower",
lab = TRUE,
lab_size = 3,
method="square",
colors = c("tomato2", "white", "springgreen3"),
title="Correlogram of Tracers",
ggtheme=theme_bw)%>% plot()
PCA <- principal(Tracers, nfactors=5, rotate="varimax", impute="mean")
PCA$loadings
Loadings:
RC1 RC3 RC2 RC4 RC5
Al 0.976 0.157
Ba 0.930 0.256 -0.131
Ca -0.549 -0.103 -0.524 0.487
Cl 0.775 0.463 -0.330
Cu 0.217 0.932
Fe 0.938 0.262 -0.143
K 0.174 0.677 0.423 -0.383
Mg 0.294 0.859 0.111
Mn 0.268 0.926
P -0.278 0.805 0.256 -0.173
S 0.936
Sr 0.148 0.237 -0.228 0.154 0.871
Zn 0.343 0.906 -0.117
SusF1 0.963 0.232
ARM 0.217 0.891 0.116
SIRM_VSM 0.945 0.262
MU -0.129 0.798 -0.174 0.133
MS 0.966 0.198
RC1 RC3 RC2 RC4 RC5
SS loadings 6.201 3.737 2.558 2.412 1.339
Proportion Var 0.344 0.208 0.142 0.134 0.074
Cumulative Var 0.344 0.552 0.694 0.828 0.903
fa.diagram(PCA$loadings)
PCA_scores <- PCA$scores %>% as.data.frame
colnames(PCA_scores) <- c("PCA_1", "PCA_2", "PCA_3", "PCA_4", "PCA_5")
describe(PCA_scores)
FA <- factanal(Tracers, factors = 4, start = NULL, nstart = 1000, rotation = "varimax", scores = 'regression')
FA$loadings
Loadings:
Factor1 Factor2 Factor3 Factor4
Al 0.973 0.174
Ba 0.926 0.271 -0.105 0.226
Ca -0.550 -0.101 -0.434 -0.229
Cl 0.994
Cu 0.205 0.930
Fe 0.932 0.285 0.124
K 0.197 0.905
Mg 0.536
Mn 0.260 0.910
P -0.257 0.819 -0.148
S 0.435 0.238
Sr 0.137 0.310 -0.333 0.103
Zn 0.330 0.924
SusF1 0.961 0.248
ARM 0.213 0.857 0.101
SIRM_VSM 0.943 0.276 -0.163
MU -0.169 -0.101 0.403
MS 0.964 0.213 -0.130
Factor1 Factor2 Factor3 Factor4
SS loadings 6.147 3.779 3.460 0.296
Proportion Var 0.342 0.210 0.192 0.016
Cumulative Var 0.342 0.551 0.744 0.760
fa.diagram(FA$loadings)
FA_scores <- FA$scores %>% as.data.frame
colnames(FA_scores) <- c("FA_1", "FA_2", "FA_3", "FA_4")
describe(FA_scores)
FAMD_Species <- FAMD(Species, graph = TRUE, axes = c(1,2))
zero-length arrow is of indeterminate angle and so skipped
FAMD scores
Map <- cbind2(Map, PCA_scores)
Map <- cbind2(Map, FA_scores)
Map <- cbind2(Map, FAMD_scores)
describe(Map)
Shapefile of the PPABC contour:
The DataSet have the coordinates and the protagonist tracer
DataSet <- cbind2(as.data.frame(Map$Latcart), as.data.frame(Map$Longcart)) %>% as.data.frame()
DataSet <- cbind2(DataSet, as.data.frame(Map$FAMD_5)) %>% as.data.frame() # INPUT THE TRACER HERE
names(DataSet)[1] <- "y"
names(DataSet)[2] <- "x"
names(DataSet)[3] <- "z"
This chunk of code in addition to the “DataSet” chunk was utilized to generate the distribution map of all factors of the multivariate statistical analisys
## akima interpolation
library(akima)
df_akima <-interp2xyz(interp(x=DataSet$x, y=DataSet$y, z=DataSet$z, duplicate="mean", linear = F,
xo=seq(min(DataSet$x), max(DataSet$x), length=30),
yo=seq(min(DataSet$y), max(DataSet$y), length=30)), data.frame=TRUE)
## akima plot
mapa <- ggmap(Capuava, extent = "device", darken = .5) +
geom_path(data = shapefile_df,
aes(x = long, y = lat, group = group),
color = 'blue', fill = 'blue', size = 2) +
geom_tile(aes(x = x, y = y, fill = z), data = df_akima, alpha = .4) +
stat_contour(aes(x = x, y = y, z = z, fill = ..level..), data = df_akima, geom = 'polygon', alpha = .4) +
geom_contour(aes(x = x, y = y, z = z), data = df_akima, colour = 'white', alpha = .4) +
scale_fill_distiller(palette = "Spectral", na.value = NA) +
geom_point(aes(x, y), data = DataSet, colour = "red", size = 1) +
labs(title = "Distribuição espacial do fator da FAMD", fill = "FAMD_5")
Ignoring unknown parameters: fill
ggsave(mapa, file = "FAMD_5.png", width = 5, height = 5, type = "cairo-png")