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
registros_BSI <- read.table("indices/indice_BSI.txt",
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
registros_IBI <- read.table("indices/indice_IBI.txt", header = TRUE, sep = ",", dec = ".")
registros_GNDVI <- read.table("indices/indice_GNDVI.txt", header = TRUE, sep = ",", dec = ".")
registros_NDVI <- read.table("indices/indice_NDVI.txt", header = TRUE, sep = ",", dec = ".")
registros_SAVI <- read.table("indices/indice_SAVI.txt", header = TRUE, sep = ",", dec = ".")
registros_EVI <- read.table("indices/indice_EVI.txt", header = TRUE, sep = ",", dec = ".") 2.2 Forest_typ v/s BSI
2.2.1 Caja de barras y bigotes para Forest_typ v/s BSI
Leyenda1 <- registros_BSI$Forest_typ
ch1 <<- ggplot(registros_BSI,aes(x=Leyenda1,y = BSI, fill=Leyenda1))+
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))
ch12.2.2 Histograma para Forest_typ v/s BSI
p <- registros_BSI %>%
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="")
pLeyenda2 <- registros_IBI$Forest_typ
ch2 <<- ggplot(registros_IBI,aes(x=Leyenda2,y=IBI,fill=Leyenda2))+
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))
ch22.2.3 Histograma para Forest_typ v/s IBI
p <- registros_IBI %>%
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="")
p2.3 Forest_typ v/s GNDVI
2.3.1 Caja de barras y bigotes para Forest_typ v/s GNDVI
library(ggplot2)
Leyenda3 <- registros_GNDVI$Forest_typ
ch3 <- ggplot(registros_GNDVI,aes(x=Leyenda3,y=GNDVI,fill=Leyenda3))+
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.
ch32.3.2 Histograma para Forest_typ v/s GNDVI
p <- registros_GNDVI %>%
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="")
p2.4 Forest_typ v/s NDVI
2.4.1 Caja de barras y bigotes para Forest_typ v/s NDVI
library(ggplot2)
Leyenda4 <- registros_NDVI$Forest_typ
ch4 <- ggplot(registros_NDVI,aes(x=Leyenda4,y=NDVI,fill=Leyenda4))+
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.
ch42.4.2 Histograma para Forest_typ v/s NDVI
p <- registros_NDVI %>%
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="")
p2.5 Forest_typ v/s SAVI
2.5.1 Caja de barras y bigotes para Forest_typ v/s SAVI
library(ggplot2)
Leyenda5 <- registros_SAVI$Forest_typ
ch5 <- ggplot(registros_SAVI,aes(x=Leyenda5,y=SAVI,fill=Leyenda5))+
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.
ch52.5.2 Histograma para Forest_typ v/s SAVI
p <- registros_SAVI %>%
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="")
p2.6 Forest_typ v/s EVI
2.6.1 Caja de barras y bigotes para Forest_typ v/s EVI
library(ggplot2)
Leyenda6 <- registros_EVI$Forest_typ
ch6 <- ggplot(registros_EVI,aes(x=Leyenda6,y=EVI,fill=Leyenda6))+
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.
ch62.6.2 Histograma para Forest_typ v/s EVI
p <- registros_EVI %>%
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="")
plibrary(patchwork)
ch <- ch1+ch3 +ch4 +ch5 +ch6 +ch2 + plot_layout(ncol = 3)+ theme(legend.position = c(-0.9, -0.7))+
theme(plot.margin = unit(c(0,0,3,0), "cm"))+
theme(legend.direction = 'horizontal')
ch <- ch + guides(fill=guide_legend(title="Legend: "))2.7 Gráficas unidas
chggsave("grafica.jpg", plot = ch, dpi = 300)