datos=read.csv("https://raw.githubusercontent.com/geovannychoez/prueba/master/abalone.data", header = FALSE)
names(datos)=c('Sex','Length','Diameter','Height','Whole_weight','Shucked_weight','Viscera_weight','Shell_weight','Rings')
library(highcharter)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
tabla_frecuencias <- as.data.frame(table(datos$Sex, datos$Rings))
# Crear el gráfico de barras
highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "Frecuencia de Sex y Rings") %>%
hc_xAxis(categories = unique(tabla_frecuencias$Var1), title = list(text = "Sex")) %>%
hc_yAxis(title = list(text = "Frecuencia")) %>%
hc_plotOptions(column = list(stacking = "normal")) %>%
hc_add_series(name = "Rings", data = tabla_frecuencias$Freq, showInLegend = FALSE) %>%
hc_tooltip(pointFormat = 'Rings: {point.y}')
# 2.2: Gráfico de barras que muestra la cantidad de abulones según el sexo.
frecuencia_sex <- as.data.frame(table(datos$Sex))
# Crear gráfico de barras para la columna 'Sex'
highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "Distribución de Sex") %>%
hc_xAxis(categories = frecuencia_sex$Var1, title = list(text = "Sex")) %>%
hc_yAxis(title = list(text = "Frecuencia")) %>%
hc_add_series(name = "Frecuencia", data = frecuencia_sex$Freq) %>%
hc_tooltip(pointFormat = 'Cantidad: {point.y}')
highchart() %>%
hc_chart(type = "scatter") %>%
hc_title(text = "Relación entre Longitud y Peso Total") %>%
hc_xAxis(title = list(text = "Longitud (Length)")) %>%
hc_yAxis(title = list(text = "Peso Total (Whole_weight)")) %>%
hc_add_series(data = list_parse2(datos[, c('Length', 'Whole_weight')]), name = "Abulones") %>%
hc_tooltip(pointFormat = 'Length: {point.x}, Weight: {point.y}')
highchart() %>%
hc_chart(type = "scatter") %>%
hc_title(text = "Relación entre Diámetro y Peso de la Cáscara") %>%
hc_xAxis(title = list(text = "Diámetro (Diameter)")) %>%
hc_yAxis(title = list(text = "Peso de la Cáscara (Shell_weight)")) %>%
hc_add_series(data = list_parse2(datos[, c('Diameter', 'Shell_weight')]), name = "Abulones") %>%
hc_tooltip(pointFormat = 'Diameter: {point.x}, Shell Weight: {point.y}')
datos_seleccionados <- datos[, c('Length', 'Diameter', 'Whole_weight', 'Rings')]
# Creación de la matriz de diagramas de dispersión
pairs(datos_seleccionados, main = "Matriz de Diagramas de Dispersión", pch = 19, col = "blue")

library(corrplot)
## corrplot 0.92 loaded
datos_seleccionados <- datos[, c('Length', 'Diameter', 'Whole_weight', 'Rings')]
# Calcular la matriz de correlación
matriz_correlacion <- cor(datos_seleccionados)
# Creación de la matriz de correlación gráfica
corrplot(matriz_correlacion, method = "circle", type = "upper",
tl.col = "black", tl.srt = 45,
title = "Matriz de Correlación de Variables Cuantitativas",
addCoef.col = "black", mar = c(0,0,2,0))

# 5) Conclusiones:
#1. Los diagramas de dispersión muestran cómo se relacionan las variables, mientras que la matriz de correlación
# cuantifica esa relación, logrando una comprensión más completa de los datos.
#2. Los gráficos generados ayudan a ver patrones de las 4 variables y los datos de la matriz de correlación
# confirman los patrones que se muestran, asegurando que las observaciones sean correctas y confiables.