library(ggplot2)
library(dplyr)
## 
## 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
data <- read.csv("C:/Users/favel/Documents/R/datos_api.csv")

data$fecha <- as.POSIXct(data$fecha.seconds, origin="1970-01-01") + data$fecha.nanoseconds / 1e9

sum(is.na(data$fecha))
## [1] 0
head(data)
##   CO humedad NH3 temperatura CO2 CH4 fecha.seconds fecha.nanoseconds
## 1  2       4   4         5.0   3   1    1712962066          49000000
## 2 50      41  75        29.2  25 100    1715057988         675000000
## 3  6      40   9        30.2   3  12    1715058175         114000000
## 4 13      14  20        30.6   6  27    1716401526          42000000
## 5 17      13  25        31.0   8  34    1716401840         644000000
## 6 48      12  72        31.4  24  96    1716402092         219000000
##                 fecha
## 1 2024-04-12 17:47:46
## 2 2024-05-06 23:59:48
## 3 2024-05-07 00:02:55
## 4 2024-05-22 13:12:06
## 5 2024-05-22 13:17:20
## 6 2024-05-22 13:21:32
ggplot(data, aes(x = fecha, y = CO)) +
  geom_line() +
  labs(title = "Concentración de CO a lo largo del tiempo", x = "Fecha", y = "Concentración de CO")

ggplot(data, aes(x = fecha, y = temperatura)) +
  geom_line(color = "blue") +
  labs(title = "Temperatura a lo largo del tiempo", x = "Fecha", y = "Temperatura")

ggplot(data, aes(x = CO, y = CO2)) +
  geom_point() +
  labs(title = "Relación entre CO y CO2", x = "Concentración de CO", y = "Concentración de CO2")

ggplot(data, aes(x = temperatura, y = humedad)) +
  geom_point(color = "red") +
  labs(title = "Relación entre Temperatura y Humedad", x = "Temperatura", y = "Humedad")
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data, aes(x = as.factor(format(fecha, "%Y-%m-%d")), y = CH4)) +
  geom_boxplot() +
  labs(title = "Distribución de CH4 por día", x = "Fecha", y = "Concentración de CH4") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

ggplot(data, aes(x = NH3)) +
  geom_histogram(binwidth = 5, fill = "green", color = "black") +
  labs(title = "Histograma de NH3", x = "Concentración de NH3", y = "Frecuencia")