R Markdown
Hello, I am extremely new at using R and have been trying to construct a time series of my air quality sensor data for about two weeks. The ultimate goal is to have 2 sensors plotted against the reference device on the same time series.
The reference data comes directly from a SQL database - I have not changed the date_time column at all.
The code that I use to extract the data into the data frame I'm using is below (link for data files):
dat.GRI1 <- read.csv("C:\\Local\\GRI1_Calibration_Consolidated_Data.csv")
dat.GRI2 <- read.csv ("C:\\Local\\GRI2_Calibration_Consolidated_Data.csv")
dat <- data.frame()
dat <- cbind.data.frame(dat.GRI1$AEROSOL, dat.GRI2$AEROSOL, stringsAsFactors = FALSE)
colnames(dat) <- c("GRI1", "GRI2")
#Convert to ug/m3 for devices
sensorData <- dat * 1000
ref.db <- read.csv("C:\\Local\\06202022_07042022_PM3_1_min_SHARP.csv", stringsAsFactors = FALSE)
sensorCal <- data.frame()
sensorCal <- cbind.data.frame(sensorData, ref.db, stringsAsFactors = FALSE)
colnames(sensorCal) <- c("GRI1", "GRI2", "Date_Time", "Ref_PM2.5", "Ref_RH", "Ref_Temp")
clean.sensorCal <- data.frame()
clean.sensorCal <- sensorCal
clean.sensorCal[clean.sensorCal < 0] <- NA
sensorCalib <- na.omit(clean.sensorCal)
colnames(sensorCalib) <- c("GRI1", "GRI2", "Date_Time", "Ref_PM2.5", "Ref_PM2.5_ppm", "Ref_RH", "Ref_Temp")
head(sensorCalib)
The code that I'm using to try and plot a time series is below:
library(tidyverse)
library(lubridate)
library(ggplot2)
sensorCalib %>%
ggplot(aes(x = as_datetime(ymd_hm(sensorCalib$Date_Time)), y = sensorCalib$GRI1,
type = "l",
col = 2,
xlim = as_datetime(c(ymd_hm("2022-06-20 10:30"), ymd_hm("2022-07-04 10:31")), tz = "GMT"),
xlab = "Date",
ylab = "PM2.5 Concentration (ug/m3)",
main = "DustTrak II vs SHARP Jun 20 - Jul 4, 2022"))
Included a SS of my console