R Markdown中没有显示的几个大时间序列图 [英] Several plots of large time series not displaying in R Markdown

查看:155
本文介绍了R Markdown中没有显示的几个大时间序列图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含16个独立时间序列的大型数据集。我想将它们绘制成3x7的网格,最上面的一行是以IN结尾的时间序列,最后一行是以OUT结尾的每个时间序列。在中间一行中,我将重复以RN结尾的两个时间序列中每一个对应于每个IN / OUT对的时间序列。我在早期的发布中获得了编写脚本的帮助,但仍然无法让R Studio输出我的图。任何智慧或指导将不胜感激。以下是我的数据集和代码:

  title:数据报告
作者: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 in knitr you need to put your plots inside a print( ) statement

Outside 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 format mm/dd/yyyy hh:mm, but the values are just decimals, and so they can't be converted into dates.

这篇关于R Markdown中没有显示的几个大时间序列图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆