我正在尝试创建一个如下所示的R降价.在一个名为app的向量中,我将有几个应用程序,将会创建一个pdf文件
--- title: "Java Based Apps" date: "January 13, 2017" output: pdf_document: number_sections: yes toc: true highlight: zenburn fig_width: 7 fig_height: 6 fig_caption: true tables: yes keep_tex: true fontsize: 12 --- ```{r message=FALSE, results = 'asis', echo=FALSE, warning=FALSE} app<-c("Sample APP") for (i in app){ cat(paste("## ", "- Correlation Analysis between performance KPI's")) cat("\n") m<-corrplot(M, method="number") cat(paste("## ", "- JVM %CPU Usage")) cat("\n") print(ggplot(data, aes(Date, JVM_CPU, group=JVM))+geom_point()+geom_smooth(method="lm",se=F)+theme_bw()+ ggtitle(paste(i, " - JVM %CPU Usage/15 Minute Interval"))+facet_wrap(~JVM, scale="free")) cat(paste("## ", "- JVM Heap Usage")) cat("\n") print(ggplot(data, aes(Date, JVM_Mem, group=JVM))+geom_point()+geom_smooth(method="lm",se=F)+theme_bw()+ ggtitle(paste(i, " - JVM Memory Usage/15 Minute Interval"))+facet_wrap(~JVM, scale="free")+ylab("Memory Usage/MG")) } ```
输出需要像这样:
Sample App - Correlation Analysis between performance KPI's - JVM %CPU Usage - JVM Heap Usage
等等
我看到了这个:
Sample App - Correlation Analysis between performance KPI's
但其他人不是作为小节创建的.知道我在这里做错了什么吗?
cat("\n\n")
在每个绘图后添加以添加空间.这应该有助于使##工作正确地分离子部分.
如果你将问题分开则更容易.我创建了一些虚假数据.
您可以拥有main.Rmd
运行for
循环的位置,例如:
title: "Java Based Apps" date: "January 13, 2017" output: pdf_document: number_sections: yes toc: true highlight: zenburn fig_width: 7 fig_height: 6 fig_caption: true tables: yes keep_tex: true fontsize: 12 --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = F, message = F, warning = F) library(tibble) library(lubridate) library(dplyr) library(corrplot) library(ggplot2) library(knitr) # Create some sample data set.seed(2887) data <- tibble( app = sort(rep(c("sample app", "sample app 2"), 500)) , Date = rep(seq(now() - as.difftime(7, unit="days"), now(), length.out = 500), 2) , JVM = sample(c("a", "b", "c"), size = 1000, replace = T) , JVM_CPU = runif(1000, 0, 100) , JVM_Mem = runif(1000, 0, 100) ) ``` ```{r} app <- sort(unique(data$app)) out <- NULL for (i in app){ data.filtered <- dplyr::filter(data, app == i) out <- c(out, knit_child('app_template.Rmd', quiet = TRUE)) } ``` `r paste(out, collapse='\n')`
你将迭代我在这里调用的模板,app_template.Rmd
看起来像这样(注意它没有yaml
:
\pagebreak # `r i` ## Correlation Analysis between performance KPI's ```{r, fig.width=5, fig.height=5} m <- matrix(rnorm(1000), ncol = 10) M <- cor(m) corrplot(M, method="number") ``` ## JVM %CPU Usage ```{r, fig.width=10, fig.height=5} ggplot(data.filtered, aes(Date, JVM_CPU, group=JVM)) + geom_point() + geom_smooth(method = "lm", se = F) + theme_bw() + ggtitle(paste(i, " - JVM %CPU Usage/15 Minute Interval")) + facet_wrap(~ JVM, scale = "free") ``` ## JVM Heap Usage ```{r, fig.width=10, fig.height=5} ggplot(data.filtered, aes(Date, JVM_Mem, group = JVM)) + geom_point() + geom_smooth(method = "lm", se = F) + theme_bw() + ggtitle(paste(i, " - JVM Memory Usage/15 Minute Interval")) + facet_wrap(~ JVM, scale = "free") + ylab("Memory Usage/MG") ```
如果你knit
,main.Rmd
你应该得到.pdf
你的规格.