mi pagina web

Author

Yoel Díaz Saucedo

1 Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

2 Mi página web

  1. Tener mi proyecto
  2. Conectar mi proyecto a GitHub
  3. Tener un archivo en html llamado “index.html”
  4. Hacer push al repositorio
  5. Activar GitHub pages

source(‘https://inkaverse.com/setup.r’)

3 Análisis de datos

3.1 Importar datos

3.1.1 forma csv

dss <- read.csv(file = "datos 2/LA MOLINA 2014 POTATO WUE (FB) - fb.csv", header = TRUE, sep = "," )

str(dss)
'data.frame':   150 obs. of  18 variables:
 $ riego  : chr  "sequia" "sequia" "irrigado" "sequia" ...
 $ geno   : chr  "G01" "G02" "G01" "G02" ...
 $ block  : int  2 4 3 1 2 5 1 4 2 1 ...
 $ bloque : chr  "II" "IV" "III" "I" ...
 $ spad_29: num  56.3 52.7 49.2 55.5 58.2 43.5 57.4 56.1 61 60.3 ...
 $ spad_83: num  41.1 47.9 41.6 44.2 32.6 37.8 42.5 35.9 57.5 41.8 ...
 $ rwc_84 : num  61.5 63.2 67.7 64.9 74.5 ...
 $ op_84  : num  -2.43 -3.03 -2.5 -2.4 -2.27 -2.37 -1.77 -2.33 -3.23 -2.87 ...
 $ leafdw : num  13.28 9.42 18.22 8.84 14.55 ...
 $ stemdw : num  14.87 8.63 24.19 6.58 12.63 ...
 $ rootdw : num  3.83 2.1 3.16 2 1.83 2.83 2.28 3.65 4.04 4.17 ...
 $ tubdw  : num  19.8 17.7 38 13.5 51.1 ...
 $ biomdw : num  51.8 37.8 83.6 30.9 80.2 ...
 $ hi     : num  0.45 0.43 0.45 0.44 0.64 0.61 0.41 0.57 0.05 0.51 ...
 $ ttrans : num  4.5 3.54 8.39 2.9 7.37 ...
 $ wue    : num  11.51 10.69 9.97 10.65 10.88 ...
 $ twue   : num  4.4 4.99 4.53 4.65 6.94 6.23 3.51 5.55 0.54 5.57 ...
 $ lfa    : int  2900 2619 7579 2450 5413 9791 7038 9794 3199 1658 ...

3.1.2 Importar datos con “url”

library(googlesheets4)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
url <-"https://docs.google.com/spreadsheets/d/15r7ZwcZZHbEgltlF6gSFvCTFA-CFzVBWwg3mFlRyKPs/edit?gid=172957346#gid=172957346"
gs<-as_sheets_id(url)

fb<-gs %>%
  range_read("fb")
! Using an auto-discovered, cached token.
  To suppress this message, modify your code or options to clearly consent to
  the use of a cached token.
  See gargle's "Non-interactive auth" vignette for more details:
  <https://gargle.r-lib.org/articles/non-interactive-auth.html>
ℹ The googlesheets4 package is using a cached token for
  '7576425921@untrm.edu.pe'.
✔ Reading from "LA MOLINA 2014 POTATO WUE (FB)".
✔ Range ''fb''.

4 Modelo lineal

modelo <- lm(formula = lfa ~ bloque + geno + riego +riego*geno , data = fb)

anova(modelo)
Analysis of Variance Table

Response: lfa
            Df    Sum Sq   Mean Sq   F value Pr(>F)    
bloque       4   3435339    858835    1.5616 0.1892    
geno        14 261729564  18694969   33.9922 <2e-16 ***
riego        1 788556926 788556926 1433.7957 <2e-16 ***
geno:riego  14 108147972   7724855   14.0457 <2e-16 ***
Residuals  116  63797516    549979                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
str(fb)
tibble [150 × 18] (S3: tbl_df/tbl/data.frame)
 $ riego  : chr [1:150] "sequia" "sequia" "irrigado" "sequia" ...
 $ geno   : chr [1:150] "G01" "G02" "G01" "G02" ...
 $ block  : num [1:150] 2 4 3 1 2 5 1 4 2 1 ...
 $ bloque : chr [1:150] "II" "IV" "III" "I" ...
 $ spad_29: num [1:150] 56.3 52.7 49.2 55.5 58.2 43.5 57.4 56.1 61 60.3 ...
 $ spad_83: num [1:150] 41.1 47.9 41.6 44.2 32.6 37.8 42.5 35.9 57.5 41.8 ...
 $ rwc_84 : num [1:150] 61.5 63.2 67.7 64.9 74.5 ...
 $ op_84  : num [1:150] -2.43 -3.03 -2.5 -2.4 -2.27 ...
 $ leafdw : num [1:150] 13.28 9.42 18.22 8.84 14.55 ...
 $ stemdw : num [1:150] 14.87 8.63 24.19 6.58 12.63 ...
 $ rootdw : num [1:150] 3.83 2.1 3.16 2 1.83 2.83 2.28 3.65 4.04 4.17 ...
 $ tubdw  : num [1:150] 19.8 17.7 38 13.5 51.1 ...
 $ biomdw : num [1:150] 51.8 37.8 83.6 30.9 80.2 ...
 $ hi     : num [1:150] 0.45 0.43 0.455 0.437 0.638 ...
 $ ttrans : num [1:150] 4.5 3.54 8.39 2.9 7.37 ...
 $ wue    : num [1:150] 11.51 10.69 9.97 10.65 10.88 ...
 $ twue   : num [1:150] 4.4 4.99 4.53 4.65 6.94 ...
 $ lfa    : num [1:150] 2900 2619 7579 2450 5413 ...
plot(modelo)

5 Diagrama de caja

library(ggplot2)

ggplot(fb, aes(x = factor(geno), y = lfa, fill = factor(riego))) +
  geom_boxplot() +
  labs(x = "genotipo" , y = "LFA" , fill = "riego") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ggtitle("Boxplot de LFA por genotipo y riego")

6 Comparación De Medias

library(agricolae)  
library(tidyverse)


#  comparación de medias para el factor geno
cat("Comparación de medias para geno:\n")
Comparación de medias para geno:
tukey_geno <- HSD.test(modelo, "geno", group = TRUE)
print(tukey_geno) 
$statistics
   MSerror  Df     Mean       CV      MSD
  549978.6 116 4806.708 15.42855 1149.464

$parameters
   test name.t ntr StudentizedRange alpha
  Tukey   geno  15         4.901424  0.05

$means
         lfa       std  r       se     Min      Max       Q25      Q50
G01 5208.740 2320.6396 10 234.5162 2900.00  7982.73 3024.7450 4871.780
G02 4248.306 1790.4189 10 234.5162 2449.59  7392.38 2705.6825 3847.175
G03 3737.911 1774.7220 10 234.5162 1811.97  5545.69 2117.7075 3790.125
G04 6323.822 3587.6820 10 234.5162 2511.13 10811.84 3062.3600 5916.390
G05 5331.217 3829.9284 10 234.5162 1657.64 10291.06 1784.2150 4586.715
G06 5401.719 2269.6009 10 234.5162 3159.54  9040.06 3398.7600 5063.420
G07 1027.445  508.7517 10 234.5162  216.31  1989.25  789.4375 1067.115
G08 4830.225 2602.1631 10 234.5162 2021.37  7643.80 2377.4100 4847.965
G09 6680.517 3942.2332 10 234.5162 2781.32 12296.22 3171.2750 5885.975
G10 4097.996 1361.9488 10 234.5162 2541.12  6164.24 2979.7125 3692.625
G11 4458.646 2830.2282 10 234.5162 1556.38  8867.09 2246.9750 3133.820
G12 4931.831 2694.8614 10 234.5162 2400.00  8603.78 2449.2350 4299.605
G13 5899.240 3000.7027 10 234.5162 3062.34  9743.70 3126.5475 5186.380
G14 5949.235 2751.9205 10 234.5162 3318.36  9776.01 3503.4825 4930.755
G15 3973.766 2529.1790 10 234.5162 1176.63  6522.46 1638.2950 4042.420
          Q75
G01  7443.612
G02  5215.847
G03  5401.852
G04  9560.083
G05  8732.257
G06  6918.457
G07  1129.532
G08  7235.692
G09 10304.727
G10  5064.198
G11  6971.368
G12  7186.702
G13  8626.745
G14  8707.917
G15  6304.358

$comparison
NULL

$groups
         lfa groups
G09 6680.517      a
G04 6323.822     ab
G14 5949.235    abc
G13 5899.240    abc
G06 5401.719    bcd
G05 5331.217   bcde
G01 5208.740  bcdef
G12 4931.831  cdefg
G08 4830.225 cdefgh
G11 4458.646  defgh
G02 4248.306   efgh
G10 4097.996    fgh
G15 3973.766     gh
G03 3737.911      h
G07 1027.445      i

attr(,"class")
[1] "group"
# comparación de medias para el factor riego
cat("Comparación de medias para riego:\n")
Comparación de medias para riego:
tukey_riego <- HSD.test(modelo, "riego", group = TRUE)
print(tukey_riego)
$statistics
   MSerror  Df     Mean       CV      MSD
  549978.6 116 4806.708 15.42855 239.8611

$parameters
   test name.t ntr StudentizedRange alpha
  Tukey  riego   2         2.801028  0.05

$means
              lfa       std  r       se     Min      Max      Q25     Q50
irrigado 7099.533 2303.6007 75 85.63322 1065.26 12296.22 6080.475 7194.26
sequia   2513.883  774.8039 75 85.63322  216.31  3811.99 1994.430 2550.51
              Q75
irrigado 8676.890
sequia   3128.035

$comparison
NULL

$groups
              lfa groups
irrigado 7099.533      a
sequia   2513.883      b

attr(,"class")
[1] "group"
# para la interaccion geno:riego
cat("Comparación de medias para la interacción geno:riego:\n")
Comparación de medias para la interacción geno:riego:
tukey_interaccion <- HSD.test(modelo, c("riego", "geno"), group = TRUE)
print(tukey_interaccion) 
$statistics
   MSerror  Df     Mean       CV      MSD
  549978.6 116 4806.708 15.42855 1803.603

$parameters
   test     name.t ntr StudentizedRange alpha
  Tukey riego:geno  30         5.438172  0.05

$means
                   lfa        std r      se     Min      Max     Q25      Q50
irrigado:G01  7377.892  583.61443 5 331.656 6539.86  7982.73 7038.08  7578.79
irrigado:G02  5779.562 1127.71742 5 331.656 4631.00  7392.38 5162.74  5233.55
irrigado:G03  5416.770   89.80871 5 331.656 5305.77  5545.69 5369.88  5412.51
irrigado:G04  9668.932  945.94448 5 331.656 8569.08 10811.84 8867.03  9791.10
irrigado:G05  8878.756 1235.57574 5 331.656 7205.94 10291.06 8189.67  8913.12
irrigado:G06  7455.364 1009.33982 5 331.656 6576.65  9040.06 6857.13  6938.90
irrigado:G07  1374.156  411.10652 5 331.656 1065.26  1989.25 1068.97  1140.05
irrigado:G08  7286.826  282.80318 5 331.656 6998.00  7643.80 7012.74  7310.01
irrigado:G09 10287.712 1548.81007 5 331.656 8533.54 12296.22 8924.78 10764.71
irrigado:G10  5271.344  822.34789 5 331.656 4249.18  6164.24 4743.16  5171.21
irrigado:G11  6854.880 1888.72290 5 331.656 3966.33  8867.09 6210.41  7225.02
irrigado:G12  7417.258  946.24681 5 331.656 6111.43  8603.78 7164.03  7194.26
irrigado:G13  8672.380 1015.60193 5 331.656 7180.79  9743.70 8256.98  8750.00
irrigado:G14  8384.132 1473.21710 5 331.656 6049.52  9776.01 7895.00  8978.89
irrigado:G15  6367.026  107.45072 5 331.656 6270.00  6522.46 6302.79  6304.88
sequia:G01    3039.588  115.85242 5 331.656 2900.00  3203.70 2994.58  2999.66
sequia:G02    2717.050  281.05239 5 331.656 2449.59  3063.35 2487.28  2618.85
sequia:G03    2059.052  179.44660 5 331.656 1811.97  2274.48 1953.50  2107.76
sequia:G04    2978.712  302.61678 5 331.656 2511.13  3263.70 2889.83  3010.27
sequia:G05    1783.678  120.66794 5 331.656 1657.64  1967.49 1700.00  1771.80
sequia:G06    3348.074  165.94367 5 331.656 3159.54  3550.19 3198.96  3381.68
sequia:G07     680.734  335.90739 5 331.656  216.31  1097.98  495.83   782.10
sequia:G08    2373.624  260.99914 5 331.656 2021.37  2697.93 2278.60  2319.71
sequia:G09    3073.322  198.12400 5 331.656 2781.32  3238.41 2961.78  3150.00
sequia:G10    2924.648  235.40497 5 331.656 2541.12  3136.07 2909.10  2940.95
sequia:G11    2062.412  317.51100 5 331.656 1556.38  2301.31 1942.23  2237.88
sequia:G12    2446.404   37.06811 5 331.656 2400.00  2487.78 2425.26  2438.98
sequia:G13    3126.100   47.70803 5 331.656 3062.34  3191.97 3110.00  3120.00
sequia:G14    3514.338  217.30731 5 331.656 3318.36  3811.99 3326.93  3449.76
sequia:G15    1580.506  248.79682 5 331.656 1176.63  1814.84 1560.00  1601.06
                  Q75
irrigado:G01  7750.00
irrigado:G02  6478.14
irrigado:G03  5450.00
irrigado:G04 10305.61
irrigado:G05  9793.99
irrigado:G06  7864.08
irrigado:G07  1607.25
irrigado:G08  7469.58
irrigado:G09 10919.31
irrigado:G10  6028.93
irrigado:G11  8005.55
irrigado:G12  8012.79
irrigado:G13  9430.43
irrigado:G14  9221.24
irrigado:G15  6435.00
sequia:G01    3100.00
sequia:G02    2966.18
sequia:G03    2147.55
sequia:G04    3218.63
sequia:G05    1821.46
sequia:G06    3450.00
sequia:G07     811.45
sequia:G08    2550.51
sequia:G09    3235.10
sequia:G10    3096.00
sequia:G11    2274.26
sequia:G12    2480.00
sequia:G13    3146.19
sequia:G14    3664.65
sequia:G15    1750.00

$comparison
NULL

$groups
                   lfa groups
irrigado:G09 10287.712      a
irrigado:G04  9668.932     ab
irrigado:G05  8878.756    abc
irrigado:G13  8672.380    abc
irrigado:G14  8384.132    bcd
irrigado:G06  7455.364    cde
irrigado:G12  7417.258    cde
irrigado:G01  7377.892    cde
irrigado:G08  7286.826    cde
irrigado:G11  6854.880    def
irrigado:G15  6367.026     ef
irrigado:G02  5779.562     ef
irrigado:G03  5416.770      f
irrigado:G10  5271.344     fg
sequia:G14    3514.338     gh
sequia:G06    3348.074     hi
sequia:G13    3126.100    hij
sequia:G09    3073.322    hij
sequia:G01    3039.588    hij
sequia:G04    2978.712    hij
sequia:G10    2924.648    hij
sequia:G02    2717.050    hij
sequia:G12    2446.404   hijk
sequia:G08    2373.624   hijk
sequia:G11    2062.412   hijk
sequia:G03    2059.052   hijk
sequia:G05    1783.678   hijk
sequia:G15    1580.506    ijk
irrigado:G07  1374.156     jk
sequia:G07     680.734      k

attr(,"class")
[1] "group"
str (tukey_interaccion) 
List of 5
 $ statistics:'data.frame': 1 obs. of  5 variables:
  ..$ MSerror: num 549979
  ..$ Df     : int 116
  ..$ Mean   : num 4807
  ..$ CV     : num 15.4
  ..$ MSD    : num 1804
 $ parameters:'data.frame': 1 obs. of  5 variables:
  ..$ test            : chr "Tukey"
  ..$ name.t          : chr "riego:geno"
  ..$ ntr             : int 30
  ..$ StudentizedRange: num 5.44
  ..$ alpha           : num 0.05
 $ means     :'data.frame': 30 obs. of  9 variables:
  ..$ lfa: num [1:30] 7378 5780 5417 9669 8879 ...
  ..$ std: num [1:30] 583.6 1127.7 89.8 945.9 1235.6 ...
  ..$ r  : int [1:30] 5 5 5 5 5 5 5 5 5 5 ...
  ..$ se : num [1:30] 332 332 332 332 332 ...
  ..$ Min: num [1:30] 6540 4631 5306 8569 7206 ...
  ..$ Max: num [1:30] 7983 7392 5546 10812 10291 ...
  ..$ Q25: num [1:30] 7038 5163 5370 8867 8190 ...
  ..$ Q50: num [1:30] 7579 5234 5413 9791 8913 ...
  ..$ Q75: num [1:30] 7750 6478 5450 10306 9794 ...
 $ comparison: NULL
 $ groups    :'data.frame': 30 obs. of  2 variables:
  ..$ lfa   : num [1:30] 10288 9669 8879 8672 8384 ...
  ..$ groups: chr [1:30] "a" "ab" "abc" "abc" ...
 - attr(*, "class")= chr "group"
mc <- tukey_interaccion$groups %>% 
  rownames_to_column("trat") %>% 
  separate(trat, c("riego", "variedad")) 


str (mc)
'data.frame':   30 obs. of  4 variables:
 $ riego   : chr  "irrigado" "irrigado" "irrigado" "irrigado" ...
 $ variedad: chr  "G09" "G04" "G05" "G13" ...
 $ lfa     : num  10288 9669 8879 8672 8384 ...
 $ groups  : chr  "a" "ab" "abc" "abc" ...

6.1 Gráfico en ggplot2

library(ggplot2)

# Crear el gráfico de barras con ggplot2
ggplot(mc, aes(x = variedad, y = lfa, fill = riego)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.9)) +   # Barras agrupadas por riego
  geom_text(aes(label = groups), position = position_dodge(0.9), vjust = -0.5) + # Etiquetas de los grupos sobre las barras
  labs(title = "Producción por Variedad y Riego", x = "Variedad", y = "LFA") +   # Etiquetas de los ejes y título
  scale_fill_manual(values = c("irrigado" = "tomato", "sequia" = "turquoise3")) + # Colores personalizados para riego
  theme_minimal() +  # Tema minimalista
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Rotar etiquetas del eje X

7 comparacion de medias: emmeans

library(emmeans)
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
mc <- emmeans(modelo,~ riego*geno)
mc <- emmeans(modelo, ~ riego|geno) 

mc <- emmeans(modelo, ~ riego|geno) %>% 
  as.data.frame()

mc
geno = G01:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  7377.892 331.656 116 6721.005  8034.779
 sequia    3039.588 331.656 116 2382.701  3696.475

geno = G02:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  5779.562 331.656 116 5122.675  6436.449
 sequia    2717.050 331.656 116 2060.163  3373.937

geno = G03:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  5416.770 331.656 116 4759.883  6073.657
 sequia    2059.052 331.656 116 1402.165  2715.939

geno = G04:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  9668.932 331.656 116 9012.045 10325.819
 sequia    2978.712 331.656 116 2321.825  3635.599

geno = G05:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  8878.756 331.656 116 8221.869  9535.643
 sequia    1783.678 331.656 116 1126.791  2440.565

geno = G06:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  7455.364 331.656 116 6798.477  8112.251
 sequia    3348.074 331.656 116 2691.187  4004.961

geno = G07:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  1374.156 331.656 116  717.269  2031.043
 sequia     680.734 331.656 116   23.847  1337.621

geno = G08:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  7286.826 331.656 116 6629.939  7943.713
 sequia    2373.624 331.656 116 1716.737  3030.511

geno = G09:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado 10287.712 331.656 116 9630.825 10944.599
 sequia    3073.322 331.656 116 2416.435  3730.209

geno = G10:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  5271.344 331.656 116 4614.457  5928.231
 sequia    2924.648 331.656 116 2267.761  3581.535

geno = G11:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  6854.880 331.656 116 6197.993  7511.767
 sequia    2062.412 331.656 116 1405.525  2719.299

geno = G12:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  7417.258 331.656 116 6760.371  8074.145
 sequia    2446.404 331.656 116 1789.517  3103.291

geno = G13:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  8672.380 331.656 116 8015.493  9329.267
 sequia    3126.100 331.656 116 2469.213  3782.987

geno = G14:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  8384.132 331.656 116 7727.245  9041.019
 sequia    3514.338 331.656 116 2857.451  4171.225

geno = G15:
 riego       emmean      SE  df lower.CL  upper.CL
 irrigado  6367.026 331.656 116 5710.139  7023.913
 sequia    1580.506 331.656 116  923.619  2237.393

Results are averaged over the levels of: bloque 
Confidence level used: 0.95 

7.1 Gráfico

ggplot(mc, aes(x = geno, y = emmean, fill = riego)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  # geom_text(aes(label = emmean), position = position_dodge(0.9), vjust = -0.5) +
  labs(x = "Variedad", y = "LFA", fill = "Riego") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

8 Análisis multivariado (Mas de 2 variables): Por correlación y PCA

8.1 Análisis de correlación

variables_cuantitativas <- fb[, c("lfa", "hi", "leafdw", "wue")]

matriz_correlacion <- cor(variables_cuantitativas, method = "pearson")

print(matriz_correlacion)
               lfa          hi     leafdw         wue
lfa     1.00000000 -0.04955964  0.7859616 -0.36555108
hi     -0.04955964  1.00000000 -0.3419763  0.08840298
leafdw  0.78596157 -0.34197634  1.0000000 -0.17692519
wue    -0.36555108  0.08840298 -0.1769252  1.00000000
library(corrplot)
corrplot 0.95 loaded
corrplot(matriz_correlacion, method = "circle", type = "upper", 
         tl.col = "black", tl.srt = 45, 
         title = "Matriz de Correlación", mar = c(0, 0, 1, 0))

library(tidyverse)
library(psych)

Adjuntando el paquete: 'psych'
The following objects are masked from 'package:ggplot2':

    %+%, alpha
fb %>%
  select_if(is.numeric) %>%
  dplyr::select(!c("block")) %>%
  pairs.panels(x = .
      , hist.col="blue"
      , pch = 21
      , stars = TRUE 
      , scale = FALSE 
      , lm= TRUE
      )

8.2 PCA análisis de componentes principales

variables_cuantitativas <- fb[sapply(fb, is.numeric)]

variables_cuantitativas_estandarizadas <- scale(variables_cuantitativas)

pca_result <- prcomp(variables_cuantitativas_estandarizadas, center = TRUE, scale. = TRUE)
summary(pca_result)
Importance of components:
                          PC1    PC2    PC3    PC4     PC5     PC6     PC7
Standard deviation     2.1734 1.8812 1.4614 1.0803 0.96150 0.93606 0.77195
Proportion of Variance 0.3149 0.2359 0.1424 0.0778 0.06163 0.05841 0.03973
Cumulative Proportion  0.3149 0.5508 0.6932 0.7710 0.83266 0.89108 0.93080
                          PC8     PC9   PC10    PC11    PC12    PC13    PC14
Standard deviation     0.6185 0.51927 0.4433 0.33408 0.24753 0.10372 0.07501
Proportion of Variance 0.0255 0.01798 0.0131 0.00744 0.00408 0.00072 0.00038
Cumulative Proportion  0.9563 0.97428 0.9874 0.99482 0.99891 0.99962 1.00000
                            PC15
Standard deviation     3.334e-16
Proportion of Variance 0.000e+00
Cumulative Proportion  1.000e+00
screeplot(pca_result, type = "lines", main = "Scree Plot")

library(ggplot2)

biplot(pca_result, main = "Biplot del PCA", cex = 0.7)

library(ggfortify)

autoplot(pca_result, data = fb, colour = 'black', loadings = TRUE, loadings.label = TRUE, 
         loadings.label.size = 3, main = "Gráfico de Componentes Principales")

8.2.1 PCA DOS EN UNO

library(FactoMineR)
library(cowplot)

Adjuntando el paquete: 'cowplot'
The following object is masked from 'package:lubridate':

    stamp
mv <- fb %>%
  group_by(riego, geno) %>%
  summarise(across(where(is.numeric), ~ mean(., na.rm = TRUE))) %>%
  PCA(scale.unit = T, quali.sup = c(1:4), graph = F)
`summarise()` has grouped output by 'riego'. You can override using the
`.groups` argument.
p1 <- plot(mv,
           choix="ind",
           habillage=1,
           label = "ind")

p2 <- plot(mv,
           choix="var")

list(p1, p2) %>%
  plot_grid(plotlist = ., nrow = 1)

9 Realizar ANOVA

anova_resultado <- aov(% DE COHESIÓN ~ factor(TRATAMIENTO), data = datos)

10 Realizar la prueba de Tukey HSD

tukey_resultado <- TukeyHSD(anova_resultado)

11 Ver los resultados de Tukey

summary(tukey_resultado)

12 Gráfico de caja para la variable “% DE COHESIÓN” por “TRATAMIENTO”

ggplot(datos, aes(x = factor(TRATAMIENTO), y = % DE COHESIÓN)) + geom_boxplot(fill = “skyblue”, color = “black”) + labs(title = “Comparación de Medias: % DE COHESIÓN por TRATAMIENTO”, x = “Tratamiento”, y = “% DE COHESIÓN”) + theme_minimal()

13 Gráficos de ggplot2

13.1 Gráficos en data cruda

13.1.1 Box plot

fb %>% 
  ggplot(data = ., aes(x = geno, y = hi, fill = riego)) +
  geom_boxplot()+
   labs(x = "Genotipos"
        , y = "Índice de cosecha"
        , fill = "Tratamiento"
        , title = "Eficiencia de uso de agua en Papa"
        , subtitle = "Índice de cosecha"
        , caption = "n = 150",) +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(family = "serif"))

13.1.2 Scater plot

fb %>% 
  ggplot(data = ., aes(x = twue, y = hi, color = riego)) +
  geom_point() +
  geom_smooth() +
  labs(x = "Genotipos"
        , y = "Índice de cosecha"
        , fill = "Tratamiento"
        , title = "Eficiencia de uso de agua en Papa"
        , subtitle = "Índice de cosecha"
        , caption = "n = 150",) +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(family = "serif"))
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'