1 Teoría de boxplots
2 Práctica: Boxplots sobre datos extraídos de imágenes satelitales
2.1 Leemos las bases de datos
BSI, IBI, GNDVI, NDVI, SAVI y EVI
<- read.table("indices/indice_BSI.txt",
registros_BSI header = TRUE, # Si se muestra el encabezado (TRUE) o no (FALSE)
sep = ",", # Separador de las columnas del archivo
dec = ".") # Caracter utilizado para separar decimales de los números en el archivo
<- read.table("indices/indice_IBI.txt", header = TRUE, sep = ",", dec = ".")
registros_IBI
<- read.table("indices/indice_GNDVI.txt", header = TRUE, sep = ",", dec = ".")
registros_GNDVI
<- read.table("indices/indice_NDVI.txt", header = TRUE, sep = ",", dec = ".")
registros_NDVI
<- read.table("indices/indice_SAVI.txt", header = TRUE, sep = ",", dec = ".")
registros_SAVI
<- read.table("indices/indice_EVI.txt", header = TRUE, sep = ",", dec = ".") registros_EVI
2.2 Forest_typ v/s BSI
2.2.1 Caja de barras y bigotes para Forest_typ v/s BSI
<- registros_BSI$Forest_typ
Leyenda1 <<- ggplot(registros_BSI,aes(x=Leyenda1,y = BSI, fill=Leyenda1))+
ch1 geom_boxplot() + labs(y = "Index value") + labs(x = "")+
geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(axis.title.y = element_text(colour = "gray"))+
scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y=0.25, label= "a)", size = 2)+ ggtitle("BSI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
ch1
2.2.2 Histograma para Forest_typ v/s BSI
<- registros_BSI %>%
p ggplot( aes(x=registros_BSI$BSI, fill=registros_BSI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
<- registros_IBI$Forest_typ
Leyenda2
<<- ggplot(registros_IBI,aes(x=Leyenda2,y=IBI,fill=Leyenda2))+
ch2
geom_boxplot() + labs(y = "Index value") + labs(x = "") +scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(axis.title.y = element_text(colour = "gray"))+
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y= 0.125, label= "b)", size = 2)+ ggtitle("IBI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
ch2
2.2.3 Histograma para Forest_typ v/s IBI
<- registros_IBI %>%
p ggplot( aes(x=registros_IBI$IBI, fill=registros_IBI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
2.3 Forest_typ v/s GNDVI
2.3.1 Caja de barras y bigotes para Forest_typ v/s GNDVI
library(ggplot2)
<- registros_GNDVI$Forest_typ
Leyenda3
<- ggplot(registros_GNDVI,aes(x=Leyenda3,y=GNDVI,fill=Leyenda3))+
ch3
geom_boxplot() + labs(y = "Index value") + labs(x = "") +scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
geom_boxplot() + labs(y = "Index value") + labs(x = "")+
theme(axis.title.y = element_text(colour = "gray"))+
scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y=1, label= "c)", size = 2)+ ggtitle("GNDVI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
ch3
2.3.2 Histograma para Forest_typ v/s GNDVI
<- registros_GNDVI %>%
p ggplot( aes(x=registros_GNDVI$GNDVI, fill=registros_GNDVI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
2.4 Forest_typ v/s NDVI
2.4.1 Caja de barras y bigotes para Forest_typ v/s NDVI
library(ggplot2)
<- registros_NDVI$Forest_typ
Leyenda4
<- ggplot(registros_NDVI,aes(x=Leyenda4,y=NDVI,fill=Leyenda4))+
ch4
geom_boxplot() + labs(y = "Index value") + labs(x = "") +scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(axis.title.y = element_text(colour = "gray"))+
scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y=1, label= "d)", size = 2)+ ggtitle("NDVI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
ch4
2.4.2 Histograma para Forest_typ v/s NDVI
<- registros_NDVI %>%
p ggplot( aes(x=registros_NDVI$NDVI, fill=registros_NDVI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
2.5 Forest_typ v/s SAVI
2.5.1 Caja de barras y bigotes para Forest_typ v/s SAVI
library(ggplot2)
<- registros_SAVI$Forest_typ
Leyenda5
<- ggplot(registros_SAVI,aes(x=Leyenda5,y=SAVI,fill=Leyenda5))+
ch5
geom_boxplot() + labs(y = "Index value") + labs(x = "") +scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(axis.title.y = element_text(colour = "gray"))+
scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y=1.4, label= "e)", size = 2)+ ggtitle("SAVI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
ch5
2.5.2 Histograma para Forest_typ v/s SAVI
<- registros_SAVI %>%
p ggplot( aes(x=registros_SAVI$SAVI, fill=registros_SAVI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
2.6 Forest_typ v/s EVI
2.6.1 Caja de barras y bigotes para Forest_typ v/s EVI
library(ggplot2)
<- registros_EVI$Forest_typ
Leyenda6
<- ggplot(registros_EVI,aes(x=Leyenda6,y=EVI,fill=Leyenda6))+
ch6
geom_boxplot() + labs(y = "Index value") + labs(x = "") +scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
geom_boxplot() + labs(y = "Index value") + labs(x = "") +
theme(axis.title.y = element_text(colour = "gray"))+
scale_fill_manual(values=c("#ff8000",
"gray",
"#6666ff",
"#33cc33",
"blue"
+
))
theme(plot.title = element_text(size=8)) +
annotate("text", x=0.6, y=3, label= "f)", size = 2)+ ggtitle("EVI")+
theme(axis.text.x = element_text(angle = 45, hjust=1)) + theme(plot.title = element_text(face = "bold")) + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "none")+ theme(text = element_text(size = 8))
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
ch6
2.6.2 Histograma para Forest_typ v/s EVI
<- registros_EVI %>%
p ggplot( aes(x=registros_EVI$EVI, fill=registros_EVI$Forest_typ)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity', bins=50) +
scale_fill_manual(values=c("#ff8000", "gray","#6666ff", "#33cc33")) +
theme_ipsum() +
labs(fill="")
p
library(patchwork)
<- ch1+ch3 +ch4 +ch5 +ch6 +ch2 + plot_layout(ncol = 3)+ theme(legend.position = c(-0.9, -0.7))+
ch theme(plot.margin = unit(c(0,0,3,0), "cm"))+
theme(legend.direction = 'horizontal')
<- ch + guides(fill=guide_legend(title="Legend: ")) ch
2.7 Gráficas unidas
ch
ggsave("grafica.jpg", plot = ch, dpi = 300)