install.packages("tidyverse")
install.packages("readxl")
# Instalamos y/o cargamos paquetes
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.3 ✔ 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
library("readxl")
read_excel()TRIGO <- read_excel("TRIGO.xlsx")
glimpse(TRIGO)
## Rows: 4,170
## Columns: 5
## $ Año <dbl> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…
## $ Localidad <chr> "CHA", "CHA", "CHA", "CHA", "CHA", "CHA", "CHA", "CHA", "C…
## $ Tratamiento <chr> "ConFung", "ConFung", "ConFung", "SinFung", "SinFung", "Si…
## $ Genotipo <chr> "KleinTauro", "KleinTauro", "KLEINCASTOR", "KleinTauro", "…
## $ Rendimiento <dbl> 5604.40, 4945.05, 6106.75, 4992.15, 5086.34, 6342.23, 5949…
RAF <- TRIGO %>%
filter(Localidad == "RAF")
RAF
## # A tibble: 366 × 5
## Año Localidad Tratamiento Genotipo Rendimiento
## <dbl> <chr> <chr> <chr> <dbl>
## 1 2007 RAF ConFung KleinTauro 5010
## 2 2007 RAF SinFung KLEINCASTOR 4942
## 3 2007 RAF ConFung KLEINCASTOR 4836
## 4 2007 RAF ConFung KleinTauro 5977
## 5 2007 RAF SinFung KleinTauro 5607
## 6 2007 RAF SinFung KleinTauro 5630
## 7 2007 RAF ConFung KleinTauro 5720
## 8 2007 RAF ConFung BUCKPUELCHE 5259.
## 9 2007 RAF ConFung BUCKPUELCHE 5586.
## 10 2007 RAF SinFung BUCKPUELCHE 4986
## # ℹ 356 more rows
## Rows: 366
## Columns: 5
## $ Año <dbl> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…
## $ Localidad <chr> "RAF", "RAF", "RAF", "RAF", "RAF", "RAF", "RAF", "RAF", "R…
## $ Tratamiento <chr> "ConFung", "SinFung", "ConFung", "ConFung", "SinFung", "Si…
## $ Genotipo <chr> "KleinTauro", "KLEINCASTOR", "KLEINCASTOR", "KleinTauro", …
## $ Rendimiento <dbl> 5010.00, 4942.00, 4836.00, 5977.00, 5607.00, 5630.00, 5720…
ggplot(TRIGO, aes(Rendimiento)) +
geom_histogram(color="blue")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Cambiamos color de los contenedores.
ggplot(RAF, aes(Rendimiento)) +
geom_histogram(color = "yellow")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Modificamos color y relleno de los contenedores.
ggplot(RAF, aes(Rendimiento)) +
geom_histogram(color = "red", fill = "black")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Ajuste de los contenedores
ggplot(RAF, aes(Rendimiento)) +
geom_histogram(bins = 13, color = "gray", fill = "lightblue") +
theme_classic()
#Paso 1: calculamos la media
kg_promedio <- mean(RAF$Rendimiento)
kg_promedio
## [1] 4361.214
ggplot(RAF, aes(Rendimiento)) +
geom_histogram(binwidth = 500, color = "green")+
geom_vline(xintercept = 4361.214, color = "red")
# Polígono de frecuencias
ggplot(RAF, aes(Rendimiento)) +
geom_freqpoly(binwidth = 500)
# Combinamos un histograma con un polígono de frecuencias
ggplot(RAF, aes(Rendimiento)) +
geom_histogram(binwidth = 500, color = "yellow") +
geom_freqpoly(binwidth = 500, color = "blue", linewidth = 1) + geom_vline(xintercept = 4361.214, color = "red")
ggplot(RAF, aes(Tratamiento, Rendimiento, color = Tratamiento)) +
geom_boxplot() +
stat_summary(fun = mean, color = "black", size = 0.8, shape = 4) +
labs(title = "Distribución del rendimiento por tratamiento",
x = "Tratamiento",
y = "Rendimiento (Kg/ha)") +
theme_classic() +
theme(plot.title = element_text(size = 12, hjust = 0.5),
axis.title.x = element_text(size = 10, color = "black"), # Tamaño de letra del título del eje x
axis.title.y = element_text(size = 10, color = "black"), # Tamaño de letra del título del eje y
axis.text.x = element_text(size = 10, color = "black"), # Tamaño de letra de las categorías del eje x
axis.text.y = element_text(size = 10, color = "black"),
legend.position = ("right"),
legend.text = element_text(size = 12), # Tamaño del texto de la leyenda
legend.title = element_text(size = 12)) + # Tamaño del título de la leyenda
scale_y_continuous(limits = c(500, 10000),breaks = seq(500, 10000, by = 1000)) + # Ajusta los límites del eje y
scale_color_manual(values = c("SinFung" = "blue", "ConFung" = "red"))
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_segment()`).
ggplot(RAF, aes(Rendimiento, group = Tratamiento, colour = Tratamiento)) +
geom_freqpoly(binwidth = 500)
install.packages("summarytools")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(summarytools)
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
## system might not have X11 capabilities; in case of errors when using dfSummary(), set st_options(use.x11 = FALSE)
##
## Attaching package: 'summarytools'
## The following object is masked from 'package:tibble':
##
## view
install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
install.packages("leaflet")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library("dplyr")
library ("leaflet")
leaflet() %>%
addProviderTiles(providers$Esri.WorldImagery) %>%
setView(lng = -61.42194444, lat = -31.2236111, zoom = 17) %>%
addMarkers(lng = -61.42194444, lat = -31.2236111)
TF_Rendimiento_RAF<- cut(RAF$Rendimiento,
breaks = seq(min(RAF$Rendimiento), max(RAF$Rendimiento), by = 500), # Ajustar el rango de los intervalos
right = FALSE, # Definir si el intervalo incluye el límite superior
include.lowest = TRUE)
freq(TF_Rendimiento_RAF,
report.nas = FALSE,
justify = "center" )
## Frequencies
## TF_Rendimiento_RAF
## Type: Factor
##
## Freq % % Cum.
## ------------------------- ------ -------- --------
## [1.35e+03,1.85e+03) 6 1.64 1.64
## [1.85e+03,2.35e+03) 5 1.37 3.01
## [2.35e+03,2.85e+03) 27 7.40 10.41
## [2.85e+03,3.35e+03) 37 10.14 20.55
## [3.35e+03,3.85e+03) 60 16.44 36.99
## [3.85e+03,4.35e+03) 59 16.16 53.15
## [4.35e+03,4.85e+03) 25 6.85 60.00
## [4.85e+03,5.35e+03) 62 16.99 76.99
## [5.35e+03,5.85e+03) 55 15.07 92.05
## [5.85e+03,6.35e+03) 18 4.93 96.99
## [6.35e+03,6.85e+03) 7 1.92 98.90
## [6.85e+03,7.35e+03] 4 1.10 100.00
## Total 365 100.00 100.00
R base# Calcular medidas de resumen
mean(RAF$Rendimiento)
## [1] 4361.214
Rendimiento <- RAF$Rendimiento
Rendimiento
## [1] 5010.00 4942.00 4836.00 5977.00 5607.00 5630.00 5720.00 5258.68 5586.09
## [10] 4986.00 4875.00 4984.00 4912.00 5020.00 5055.64 5202.96 5832.45 5209.37
## [19] 5948.63 5713.18 5238.00 5881.00 5658.00 5528.00 5325.00 6031.00 5224.00
## [28] 5066.84 5414.00 5631.70 4955.31 5239.00 5089.53 5273.86 5439.00 5144.00
## [37] 5129.05 5218.00 5472.52 5226.00 5093.00 4798.00 5392.00 4995.00 3434.00
## [46] 5410.00 4938.00 5533.16 5092.00 5505.46 4768.00 5140.00 5700.60 4906.00
## [55] 2647.00 2986.00 2740.00 3187.00 1935.00 2994.00 2059.00 2356.00 4307.00
## [64] 3122.00 2753.00 2635.00 2822.00 3412.00 2629.00 4249.00 2313.00 3696.00
## [73] 2288.00 2651.00 2717.00 4208.10 4109.60 2735.90 4358.60 3277.70 3039.00
## [82] 4014.10 3600.60 3363.70 2845.90 4085.60 4287.00 3867.30 4158.10 2622.10
## [91] 2771.90 3300.40 3749.20 3416.10 4009.70 3213.60 3769.20 4770.20 3673.70
## [100] 3217.90 3535.30 4166.50 4139.50 4791.50 4725.60 4343.40 3111.90 3892.60
## [109] 3367.50 4317.90 3966.50 4325.40 4156.70 3734.90 3382.40 3289.40 4218.20
## [118] 4281.70 3972.50 2803.20 3813.30 4083.00 3040.30 4275.70 3626.00 3763.60
## [127] 3302.90 3404.70 3530.50 3702.70 3993.30 4267.40 4418.00 3092.40 3195.80
## [136] 3725.90 4547.50 4179.50 3743.50 3860.30 3542.30 2968.50 3397.40 4090.10
## [145] 3645.80 3893.90 3385.70 4385.60 4427.90 3794.10 4008.20 3147.00 3098.10
## [154] 3715.90 3683.70 3595.50 3687.80 3520.80 3143.00 3797.30 3588.00 2835.10
## [163] 2733.00 4230.90 3658.70 3896.90 3928.80 3397.30 4343.80 3802.80 3378.60
## [172] 4346.00 4215.50 3535.30 3500.80 3880.70 3734.90 4103.80 3360.00 3217.50
## [181] 2766.50 4051.50 3932.60 3913.00 3307.70 3385.70 2996.70 3060.30 3360.00
## [190] 3538.80 3471.50 3650.60 2738.60 4287.00 4000.60 3480.30 2367.40 3266.60
## [199] 4343.80 5077.40 3195.40 2831.90 4370.90 4472.40 4561.90 4937.80 3757.20
## [208] 3523.50 3210.00 2999.10 4154.30 3282.00 4492.30 4753.00 5843.00 5512.00
## [217] 5516.00 4851.00 5441.00 5540.00 5255.00 5979.00 5328.00 6011.00 5556.00
## [226] 5465.00 3766.00 5751.00 5235.00 4889.00 5603.00 5430.00 5226.00 4989.00
## [235] 5026.00 7455.00 6293.00 5879.00 6433.00 5001.00 5226.00 5258.00 5382.00
## [244] 6857.00 6647.00 5755.00 6487.00 6038.00 5765.00 5597.00 7014.00 5252.00
## [253] 5202.00 5198.00 6929.00 6178.00 5407.00 5755.00 5681.00 5653.00 5121.00
## [262] 5164.00 4657.00 6367.00 6564.00 5276.00 5602.00 5736.00 5160.00 5045.00
## [271] 4389.00 5523.00 6750.00 5389.00 5574.00 5523.00 4739.00 4840.00 4441.00
## [280] 5169.00 6153.00 4830.00 5134.00 5595.00 5918.00 5514.00 5578.00 5579.00
## [289] 5696.00 5958.00 5024.00 5267.00 5893.00 4962.00 6176.00 5533.00 5415.00
## [298] 5823.00 5038.00 5778.00 2312.00 5174.00 5635.00 6402.00 6203.00 5208.00
## [307] 4829.00 5609.00 4987.00 4294.00 6958.00 5591.00 5500.00 4964.00 4016.00
## [316] 5767.00 4597.00 5994.00 5289.00 5329.00 6035.00 4071.00 4319.00 3267.00
## [325] 3659.00 3043.00 2992.00 1612.00 1774.00 4510.00 2590.00 3063.00 2748.00
## [334] 2841.00 4100.00 3889.00 2973.00 3408.00 3810.00 3864.00 3793.00 4345.00
## [343] 4011.00 3382.00 2663.00 2383.00 2940.00 2703.00 2808.00 3511.00 1370.00
## [352] 1409.00 1621.00 1350.00 3903.00 3680.00 3910.00 3809.00 3323.00 3770.00
## [361] 3289.00 3229.00 4116.00 3412.00 4209.00 4190.00
TRIGO <- TRIGO %>%
mutate(Tratamiento_Rafaela = case_when(
Tratamiento == "SinFung" ~ "Sin Funguicida",
Tratamiento == "ConFung" ~ "Con Funguicida"))
TRIGO
## # A tibble: 4,170 × 6
## Año Localidad Tratamiento Genotipo Rendimiento Tratamiento_Rafaela
## <dbl> <chr> <chr> <chr> <dbl> <chr>
## 1 2007 CHA ConFung KleinTauro 5604. Con Funguicida
## 2 2007 CHA ConFung KleinTauro 4945. Con Funguicida
## 3 2007 CHA ConFung KLEINCASTOR 6107. Con Funguicida
## 4 2007 CHA SinFung KleinTauro 4992. Sin Funguicida
## 5 2007 CHA SinFung KleinTauro 5086. Sin Funguicida
## 6 2007 CHA SinFung KleinTauro 6342. Sin Funguicida
## 7 2007 CHA ConFung KleinTauro 5950. Con Funguicida
## 8 2007 CHA ConFung KLEINCASTOR 5447. Con Funguicida
## 9 2007 CHA SinFung BUCKPUELCHE 4898. Sin Funguicida
## 10 2007 CHA ConFung BUCKPUELCHE 5557. Con Funguicida
## # ℹ 4,160 more rows
TRIGO %>%
group_by(Tratamiento_Rafaela) %>%
descr(Rendimiento,
headings = FALSE,
justify = "center")
##
## Con Funguicida Sin Funguicida
## ----------------- ---------------- ----------------
## Mean 5051.55 4641.55
## Std.Dev 1545.28 1454.22
## Min 832.00 432.00
## Q1 4010.00 3635.00
## Median 5076.32 4716.50
## Q3 6071.00 5692.00
## Max 9036.00 8400.00
## MAD 1544.13 1517.44
## IQR 2060.00 2053.00
## CV 0.31 0.31
## Skewness -0.12 -0.17
## SE.Skewness 0.06 0.05
## Kurtosis -0.16 -0.40
## N.Valid 1754.00 2416.00
## Pct.Valid 100.00 100.00
summary(Rendimiento)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1350 3443 4287 4361 5265 7455
Resumen_tidy <- RAF %>%
summarise(Media = mean(Rendimiento),
Mediana = median(Rendimiento),
Rango = paste(range(Rendimiento), collapse = " - "),
Std = sd(Rendimiento))
Resumen_tidy
## # A tibble: 1 × 4
## Media Mediana Rango Std
## <dbl> <dbl> <chr> <dbl>
## 1 4361. 4287 1350 - 7455 1155.
Rendimiento_promedio <- RAF %>%
group_by(Genotipo, Tratamiento) %>%
summarise(Rendimiento_promedio = mean(Rendimiento, na.rm = TRUE)) %>%
arrange(desc(Rendimiento_promedio)) # Ordenar de mayor a menor rendimiento
## `summarise()` has grouped output by 'Genotipo'. You can override using the
## `.groups` argument.
Mejor_genotipo <- Rendimiento_promedio %>%
group_by(Tratamiento) %>%
slice(1) # Tomar el genotipo con mayor rendimiento por tratamiento
Mejor_genotipo
## # A tibble: 2 × 3
## # Groups: Tratamiento [2]
## Genotipo Tratamiento Rendimiento_promedio
## <chr> <chr> <dbl>
## 1 ONIX ConFung 5831.
## 2 ACA905 SinFung 5543.