R Markdown中没有显示的几个大时间序列图 [英] Several plots of large time series not displaying in R Markdown
问题描述
title:数据报告
$ p $
作者:Dr.Vini42
日期:2016年2月17日
输出:word_document
---
$ b $```{r,echo = FALSE}
library(ggplot2)
numbers < - read.csv(./ AllData.csv,header = TRUE)
num < - (ncol(numbers)-4)/ 4 * 3#将36列转换为24涉及8个时间序列的地块
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),数字[[4 * i + 2]],xlab =日期,ylab =Feet,main = names(numbers)[4 * i + 2])
} else if(i <15){
qplot(as.Date(numbers [ 4 * i-6]],%m /%d /%Y%H:%M),数字[[4 * i-5]],xlab =Date,ylab =Feet名称(数字)[4 * i-5])
}其他{
qplot(as.Date(数字[[4 * i-13]],%m /%d /%Y% H:%M),数字[[4 * i-12]],xlab =Date,ylab =Feet, main = names(numbers)[4 * i-12])
}
}
```
for()
循环中的$
knitr
你需要把你的情节放在print()
语句中
循环
knitr
认识到它需要打印并为您完成。```{r}
...
$如果(i <8){
print(qplot(as.Date)),则b $ b par(mfrow = c(3,7))
(i in 1:num) (数字[[4 * i + 1]],%m /%d /%Y%H:%M),数字[[4 * i + 2]],xlab =Date,ylab = ,main = names(numbers)[4 * i + 2]))
} else {
...
}
}
` ``
更新
我通常不会下载整个文件来测试代码,但是,我做了一个例外...
要查看您的问题,请运行这些行
i < - 1
as.Date(numbers [[4 * i + 2]],% m /%d /%Y%H:%M)##这应该是错误
数字[[6]] ##这显示数据
您试图将
数字[[6]]
(第6列)中的数据转换为日期格式为mm / dd / yyyy hh:mm
,但这些值只是小数,因此它们不能转换为日期。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.```{r} ... par(mfrow=c(3,7)) for(i in 1:num){ if (i < 8) { print( 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 { ... } } ```
Update
I don't normally download whole files to test code, but, I've made an exception...
To see your issue, run these lines
i <- 1 as.Date(numbers[[4*i+2]],"%m/%d/%Y %H:%M") ## this should error numbers[[6]] ## this shows you the data
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.这篇关于R Markdown中没有显示的几个大时间序列图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!