I have a large dataset of 16 independent timeseries. I would like to plot them in a 3x7 grid with the top row being each of the timeseries ending in IN and the bottom row being each of the timeseries ending in OUT. In the middle row, I will repeat each of the two timeseries ending in RN that corresponds to each IN/OUT couple. I have set up what I believe to be the necessary logic and syntax to accomplish, but I continue to struggle with data classes and can't get the script to run long enough to debug the rest. I am fairly new at R, so I am unsure of how to proceed.
library(ggplot2)
numbers <- read.csv("./AllData.csv", header=TRUE)
num <- (ncol(numbers) - 4)/4*3 #converts 36 columns to 24 plots involving 8 timeseries
par(mfrow=c(3,7))
for(i in 1:num){
if (i < 8) {
qplot(as.POSIXct(as.Date(numbers[4*i+1])), numbers[4*i+2], data="numbers", xlab="Date", ylab="Feet", main=numbers[4*i+2,1])
} else if (i < 15) {
qplot(as.POSIXct(as.character(numbers[4*i-6]), format="%m/%d/%Y %H:%M"), numbers[4*i-5], data="numbers", xlab="Date", ylab="Feet", main=numbers[4*i-5,1])
} else {
qplot(as.POSIXct(as.character(numbers[4*i-13]), format="%m/%d/%Y %H:%M"), numbers[4*i-12], data="numbers", xlab="Date", ylab="Feet", main=numbers[4*i-12,1])
}
In place of "as.POSIXct," I have also tried "as.Date," "as.POSIXlt," and simply plotting the dataset as is, but all result in similar errors informing me that ggplot can't use whatever class I have in use. I have tried using the basic plot function below, but then receive errors that my x and y are of different lengths, which I have checked and are of equal lengths.
par(mfrow=c(3,7))
for(i in 1:num){
if (i < 8) {
x <- as.POSIXct(as.character(numbers[4*i+1]), format="%m/%d/%Y %H:%M")
x <- numbers[4*i+1]
y <- numbers[4*i+2]
main <- numbers[4*i+2,1]
} else if (i < 15) {
x <- as.POSIXct(as.character(numbers[4*i-6]), format="%m/%d/%Y %H:%M")
y <- numbers[4*i-5]
main <- numbers[4*i-5,1]
} else {
x <- as.POSIXct(as.character(numbers[4*i-13]), format="%m/%d/%Y %H:%M")
y <- numbers[4*i-12]
main <- numbers[4*i-12,1]
}
plot(x, y, type="l", xlab="Date", ylab="Feet", heading=main)
}
Any wisdom or guidance would be appreciated. Here is my dataset: https://drive.google.com/file/d/0BzEFYP8cpjHpUlluSlNZaTN1RDA/view?usp=sharing