1. Introduccion
Para este ejemplo necesitamos cargas los siguientes paquetes
library(agricolae)
library(corrplot)
Usaremos el data(soil)
el cual es un dataset del paquete agricolae de un analisis fisico-quimico de suelo para diferentes zonas de muestreo, para mas informacion puede usar ?soil
place | pH | EC | CaCO3 | MO | CIC | P | K | sand | slime | clay | Ca | Mg | K2 | Na | Al_H | K_Mg | Ca_Mg | B | Cu | Fe | Mn | Zn |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Namora | 3.8 | 0.72 | 0.0 | 1.7 | 5.76 | 8.1 | 28 | 80 | 16 | 4 | 0.74 | 0.15 | 0.10 | 0.27 | 1.2 | 0.6666667 | 4.933333 | 0.9 | 0.4 | 295.4 | 1.3 | 2.1 |
Hyo1 | 7.2 | 1.00 | 1.4 | 2.6 | 20.00 | 17.5 | 166 | 26 | 42 | 32 | 17.21 | 2.06 | 0.47 | 0.26 | 0.0 | 0.2281553 | 8.354369 | 0.2 | 12.1 | 12.9 | 0.5 | 62.2 |
Hyo2 | 8.4 | 0.32 | 9.6 | 2.0 | 18.88 | 17.6 | 124 | 44 | 32 | 24 | 14.91 | 3.37 | 0.36 | 0.24 | 0.0 | 0.1068249 | 4.424332 | 0.4 | 2.5 | 23.2 | 7.9 | 6.7 |
SR1 | 4.8 | 0.83 | 0.0 | 1.9 | 17.28 | 15.8 | 86 | 58 | 30 | 12 | 12.49 | 1.90 | 0.26 | 0.32 | 0.4 | 0.1368421 | 6.573684 | 0.5 | 3.0 | 352.4 | 5.1 | 7.0 |
SR2 | 4.4 | 0.49 | 0.0 | 2.0 | 6.40 | 7.2 | 30 | 78 | 14 | 8 | 0.76 | 0.13 | 0.09 | 0.26 | 0.9 | 0.6923077 | 5.846154 | 0.4 | 0.6 | 334.4 | 1.8 | 1.7 |
Cnt1 | 7.6 | 1.09 | 0.9 | 1.3 | 13.60 | 8.9 | 350 | 48 | 38 | 14 | 10.56 | 1.79 | 0.88 | 0.37 | 0.0 | 0.4916201 | 5.899441 | 2.5 | 5.1 | 12.9 | 2.1 | 3.1 |
Cnt2 | 8.3 | 3.67 | 7.6 | 1.7 | 22.08 | 20.0 | 537 | 36 | 36 | 28 | 15.60 | 4.44 | 1.42 | 0.62 | 0.0 | 0.3198198 | 3.513514 | 3.1 | 1.7 | 4.3 | 2.1 | 8.3 |
Cnt3 | 8.4 | 7.17 | 2.7 | 1.1 | 13.92 | 50.0 | 414 | 50 | 28 | 22 | 9.57 | 2.67 | 0.76 | 0.92 | 0.0 | 0.2846442 | 3.584270 | 4.9 | 1.5 | 16.3 | 4.6 | 6.3 |
Chz | 6.1 | 0.15 | 0.0 | 1.6 | 12.48 | 8.5 | 84 | 52 | 28 | 20 | 8.65 | 1.54 | 0.25 | 0.29 | 0.0 | 0.1623377 | 5.616883 | 0.4 | 1.9 | 315.9 | 20.6 | 3.2 |
Chmar | 4.4 | 0.18 | 0.0 | 3.8 | 25.60 | 44.1 | 240 | 68 | 26 | 6 | 3.08 | 0.56 | 0.56 | 0.27 | 2.6 | 1.0000000 | 5.500000 | 1.1 | 2.3 | 1160.0 | 7.6 | 4.5 |
Hco1 | 4.7 | 0.84 | 0.0 | 2.5 | 19.36 | 20.1 | 57 | 44 | 46 | 10 | 11.80 | 6.25 | 0.15 | 0.31 | 0.3 | 0.0240000 | 1.888000 | 0.7 | 1.1 | 257.6 | 3.6 | 2.6 |
Hco2 | 6.2 | 0.09 | 0.0 | 1.7 | 14.08 | 3.6 | 65 | 42 | 34 | 24 | 8.04 | 4.35 | 0.19 | 0.25 | 0.0 | 0.0436782 | 1.848276 | 0.0 | 2.5 | 1275.0 | 10.3 | 2.9 |
Hco3 | 5.7 | 0.21 | 0.0 | 5.4 | 20.80 | 47.1 | 452 | 46 | 44 | 10 | 7.44 | 2.27 | 1.11 | 0.26 | 1.5 | 0.4889868 | 3.277533 | 0.3 | 6.0 | 1715.0 | 10.4 | 5.0 |
2. Hacer la correlación
En este caso haremos una correlacion de Pearson.
cor(soil[,2:23]
indica que hemos solo seleccionado las variables numericas, porque se debe excluir la columna con los nombres de los lugares de muestreo y los asignamos a una variable x
x <- cor(soil[,2:23], method = "pearson")
corrplot(x,method = "square", type = "upper", bg = "white",
diag = F, outline =T, tl.col = "black",
order = "AOE", tl.srt = 45
)
Para mayor personalización del grafico puede ver la documentacion con la función ?corrplot