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 received assistance writing the script in an earlier post, but still cannot get R Studio to output my plots. Any wisdom or guidance would be appreciated. Here are my dataset and code:
title: "Data Report"
author: "Dr.Vini42"
date: "February 17, 2016"
output: word_document
---
```{r, echo=FALSE}
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.Date(numbers[[4*i+1]],"%m/%d/%Y %H:%M"), numbers[[4*i+2]], xlab="Date", ylab="Feet", main=names(numbers)[4*i+2])
} else if (i < 15) {
qplot(as.Date(numbers[[4*i-6]],"%m/%d/%Y %H:%M"), numbers[[4*i-5]], xlab="Date", ylab="Feet", main=names(numbers)[4*i-5])
} else {
qplot(as.Date(numbers[[4*i-13]],"%m/%d/%Y %H:%M"), numbers[[4*i-12]], xlab="Date", ylab="Feet", main=names(numbers)[4*i-12])
}
}
```
In a
for( )
loop inknitr
you need to put your plots inside aprint( )
statementOutside of the loop
knitr
recognises it needs to print and does it for you. Inside the loop it doesn't.Update
I don't normally download whole files to test code, but, I've made an exception...
To see your issue, run these lines
You are trying to convert the data in
numbers[[6]]
(the 6th column) to a date in the formatmm/dd/yyyy hh:mm
, but the values are just decimals, and so they can't be converted into dates.