library(readxl)
## Warning: package 'readxl' was built under R version 4.1.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(clhs)
## Warning: package 'clhs' was built under R version 4.1.3
library(ClustGeo)
## Warning: package 'ClustGeo' was built under R version 4.1.3
df <- read_excel("C:/Users/usuagro/Downloads/BD_MODELADO.xlsx")
df %>%
ggplot(aes(Avg_X_MCB,Avg_Y_MCE,
color=Avg_CEa_07))+
geom_point(size=3)+
coord_equal()
D0 = dist(df$Avg_CEa_07)
tree = hclustgeo(D0)
groups= cutree(tree,2)
df$Clusters = groups
df %>%
ggplot(aes(Avg_X_MCB,Avg_Y_MCE,
color=as.factor(Clusters)))+
geom_point(size=3)+
coord_equal()
# EstadÃsticas por grupo
df %>%
group_by(Clusters) %>%
summarise(mediat=mean(Avg_CEa_07,
trim=0.05),
media = mean(Avg_CEa_07),
mediana=median(Avg_CEa_07),
n=n())
## # A tibble: 2 x 5
## Clusters mediat media mediana n
## <int> <dbl> <dbl> <dbl> <int>
## 1 1 8.86 8.80 9.00 193
## 2 2 11.3 11.3 11.2 120
df_1 = df%>%
select(Avg_X_MCB,
Avg_Y_MCE,
Avg_CEa_07)
res = clhs(x = df_1,size = 60)
df_1[res,] %>%
ggplot(aes(x=Avg_X_MCB,
y=Avg_Y_MCE,
color=Avg_CEa_07))+
geom_point(size=3)
table(df[res,]$Clusters)
##
## 1 2
## 37 23
tapply(df[res,]$Avg_CEa_07,
df[res,]$Clusters,
mean)
## 1 2
## 8.817569 11.333361
ggplot(data = df,
aes(x=Avg_X_MCB,
y=Avg_Y_MCE,
color=as.factor(Clusters)))+
geom_point(size=2)+
geom_point(data = df[res,],
aes(x=Avg_X_MCB,
y=Avg_Y_MCE),
color="black",
shape=5,
size=5)
df %>%
ggplot(aes(x=Avg_X_MCB,y=Avg_Y_MCE,
color=NDVI))+
geom_point(size=4)+
scale_color_viridis_c()+
theme_minimal()+
coord_equal()
#NDVI
d= dist(df[,c(3)])
tree <- hclustgeo(d)
groups <- cutree(tree,2)
df$grupo1 = groups
q6=df %>%
ggplot(aes(x=Avg_X_MCB,
y=Avg_Y_MCE,
color=as.factor(grupo1)))+
geom_point(size=4)+
theme_minimal()+
coord_equal()+
labs(title="CEa_7")