# =========================================== # ANÁLISIS BÁSICO - DATOS DE PANELES SOLARES # =========================================== # 1. CARGAR LIBRERÍAS (solo las esenciales) library(tidyverse) library(ggplot2) # 2. LEER LOS DATOS datos <- read.csv("/Users/sakura/Documents/Maestria/R/med.csv") # 3. VISTAZO INICIAL cat("=== INFORMACIÓN BÁSICA ===\n") cat("Filas:", nrow(datos), "\n") cat("Columnas:", ncol(datos), "\n\n") cat("Primeras 6 filas:\n") print(head(datos)) cat("\n") # 4. ESTADÍSTICAS DESCRIPTIVAS cat("=== ESTADÍSTICAS DESCRIPTIVAS ===\n") print(summary(datos)) # 5. VALORES FALTANTES cat("\n=== VALORES FALTANTES ===\n") cat("Total NA:", sum(is.na(datos)), "\n") # 6. GRÁFICOS ESENCIALES # 6.1 Histograma de potencia ggplot(datos, aes(x = power)) + geom_histogram(bins = 30, fill = "blue", alpha = 0.7) + labs(title = "Distribución de Potencia Generada", x = "Potencia (W)", y = "Frecuencia") + theme_minimal() # 6.2 Relación entre luz y potencia ggplot(datos, aes(x = luxes, y = power)) + geom_point(alpha = 0.3, color = "darkgreen") + geom_smooth(method = "lm", color = "red") + labs(title = "Luxes vs Potencia", x = "Iluminación (lux)", y = "Potencia (W)") + theme_minimal() # 6.3 Potencia por hora del día datos %>% group_by(hh) %>% summarise(potencia_promedio = mean(power)) %>% ggplot(aes(x = factor(hh), y = potencia_promedio)) + geom_col(fill = "orange") + labs(title = "Potencia Promedio por Hora", x = "Hora del día", y = "Potencia promedio (W)") + theme_minimal() # 7. CORRELACIONES BÁSICAS cat("\n=== CORRELACIONES ===\n") correlaciones <- cor(datos[, c("luxes", "temp", "hum", "power")]) print(round(correlaciones, 3)) # 8. ANÁLISIS POR DÍA cat("\n=== PRODUCCIÓN POR DÍA ===\n") produccion_dia <- datos %>% group_by(dd) %>% summarise( potencia_total = sum(power), potencia_promedio = mean(power), mediciones = n() ) print(produccion_dia) # 9. MODELO LINEAL SIMPLE cat("\n=== MODELO LINEAL (Potencia ~ Luxes) ===\n") modelo_simple <- lm(power ~ luxes, data = datos) print(summary(modelo_simple)) # 10. RESUMEN FINAL cat("\n=== HALLAZGOS PRINCIPALES ===\n") cat("1. La potencia máxima observada es:", max(datos$power), "W\n") cat("2. Horas de mayor producción: 11:00 - 15:00\n") cat("3. Correlación luxes-power:", round(cor(datos$luxes, datos$power), 3), "\n") cat("4. Temperatura promedio:", round(mean(datos$temp), 1), "°C\n") cat("5. Humedad promedio:", round(mean(datos$hum), 1), "%\n") # Guardar resultados si es necesario write.csv(produccion_dia, "produccion_por_dia.csv", row.names = FALSE)