# Muestreo espacial latino

library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
xy = expand.grid(x = 1:90, y = c(1:5, 7:11))
plot(xy)

xy$lote = NA 
xy$lote[(xy$x%in%1:60)&(xy$y%in%1:5)] = 'V1-A'
xy$lote[(xy$x%in%61:90)&(xy$y%in%1:5)] = 'V2-A'
xy$lote[(xy$x%in%1:60)&(xy$y%in%7:11)] = 'V1-B'
xy$lote[(xy$x%in%61:90)&(xy$y%in%7:11)] = 'V2-B'

graf_lote = ggplot(xy[xy$lote!='corredor',])+
  aes(x,y, fill=lote)+
  geom_tile(color='white')
graf_lote

# Muestreo hipercubo latino 

xy = expand.grid(x = 1:90, y = c(1:5, 7:11))
dim(xy)
## [1] 900   2
head(xy)
##   x y
## 1 1 1
## 2 2 1
## 3 3 1
## 4 4 1
## 5 5 1
## 6 6 1
variedad=gl(2,450,900,labels = c("variedad1","variedad2"))
fen=gl(3,150,900,labels = c("T45","T70","T65"))
thrips=round(runif(900,0,0.65),0)
hongos=round(runif(900,0,0.52),0)
babosa=round(runif(900,0,0.54),0)
NDVI=sort(runif(900,0.66,0.80))
df=data.frame(xy,variedad,fen,thrips,hongos,babosa,NDVI)
head(df)
##   x y  variedad fen thrips hongos babosa      NDVI
## 1 1 1 variedad1 T45      0      0      0 0.6601039
## 2 2 1 variedad1 T45      1      0      0 0.6601586
## 3 3 1 variedad1 T45      1      0      0 0.6604764
## 4 4 1 variedad1 T45      0      0      0 0.6606062
## 5 5 1 variedad1 T45      0      0      0 0.6606750
## 6 6 1 variedad1 T45      0      0      0 0.6606812
library(clhs)
## Warning: package 'clhs' was built under R version 4.2.3
res <- clhs(df, size = 50, progress = FALSE, simple = TRUE)
res
##  [1] 784 870 298 801 393 114 592  67 205 755 612 170 554 816  31 630 359 371 189
## [20] 536 486 434 650 832 108 255 894 311 414 692 460 758 518 500 250   8 225 631
## [39] 678  83 282 146 857 129  44 327 568 423 736 707

¿ graficar cuàntos salieron de cada variedad,fen,…?

puntos de muestreo

library(ggplot2)

# Crear objeto ggplot con los datos
graf_fen <- ggplot(df, aes(x = x, y = y, color = fen)) +
             geom_point()

# Mostrar gráfico
print(graf_fen)

library(ggplot2)

# Crear objeto ggplot con los datos
graf_thrips <- ggplot(df, aes(x = x, y = y, color = thrips)) +
             geom_point()

# Mostrar gráfico
print(graf_thrips)

library(ggplot2)

# Crear objeto ggplot con los datos
graf_hongos <- ggplot(df, aes(x = x, y = y, color = hongos)) +
             geom_point()

# Mostrar gráfico
print(graf_hongos)

library(ggplot2)

# Crear objeto ggplot con los datos
graf_babosa <- ggplot(df, aes(x = x, y = y, color = babosa)) +
             geom_point()

# Mostrar gráfico
print(graf_babosa)

library(ggplot2)

# Crear objeto ggplot con los datos
graf_ndvi <- ggplot(df, aes(x = x, y = y, color = NDVI)) +
             geom_point()

# Mostrar gráfico
print(graf_ndvi)#el color de cada punto representa el valor de NDVI en ese punto.