如何在R-Markdown中立即制作多个针织?
我仍在寻找您可以提供的任何帮助:)
我正在制作一个充满工作统计数据的Onepager。我得到了70种不同的工作,这意味着我需要制作70个OnePagers。如何自动化降级以一次制作70个?
我只用两个基本图制作了简化的降价版本。我该如何做到这一点,以便在我编织3个作业的示例中,我会在每个onepager上获得3个带有正确统计数据的OnePagers,并将其保存到“ C:/users/desktop/onepagers/”中,将作业作为PDF名称。例如:Analyst.pdf,Doctor.pdf和Pilot.pdf
第1页上的第一个DF是:
Job GENDER PEOPLE Analyst M 500 Analyst F 1000 Doctor M 2500 Doctor F 2000 Pilot M 50 Pilot F 10
第2页上的第二df是:
JOB AGE PEOPLE Analyst Under 30 400 Analyst 31-40 700 Analyst 41-50 300 Analyst Over 50 100 Doctor Under 30 500 Doctor 31-40 1500 Doctor 41-50 1500 Doctor Over 50 1000 Pilot Under 30 10 Pilot 31-40 25 Pilot 41-50 20 Pilot Over 50 5
---
title: "Name of job"
output: pdf_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(readxl)
options(scipen = 100)
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE, fig.width=4, fig.height=2.5}
GENDER <- read_xlsx("C:/Users/Desktop/TEST_MARKDOWN.xlsx", sheet=1)
GENDER <- filter(GENDER, JOB == "Analyst")
ggplot(GENDER,aes(y=GENDER, x=PEOPLE))+
geom_bar(stat = 'identity')+
theme_minimal()
```
```{r, echo=FALSE, fig.width=3.7, fig.height=2.5}
AGE <- read_xlsx("C:/Users/Desktop/TEST_MARKDOWN.xlsx", sheet=2)
AGE <- filter(AGE, JOB == "Analyst")
ggplot(AGE,aes(y=AGE, x=PEOPLE))+
geom_bar(stat = 'identity')+
theme_minimal()
```
I'm still looking for any help you can provide :)
I'm making a onepager that is full of different stats on jobs. I got 70 different jobs that means i need to make 70 onepagers. How can i automate markdown to make all 70 at once?
I made a simplified markdown version with just two basic plots. How can i make it so that in my example with 3 jobs when i knit i get 3 onepagers with the correct stats on each onepager and save them to "C:/Users/Desktop/Onepagers/" with the job as the pdf name. For example: Analyst.pdf , Doctor.pdf and Pilot.pdf
First DF on sheet 1 is:
Job GENDER PEOPLE Analyst M 500 Analyst F 1000 Doctor M 2500 Doctor F 2000 Pilot M 50 Pilot F 10
Second DF on sheet 2 is:
JOB AGE PEOPLE Analyst Under 30 400 Analyst 31-40 700 Analyst 41-50 300 Analyst Over 50 100 Doctor Under 30 500 Doctor 31-40 1500 Doctor 41-50 1500 Doctor Over 50 1000 Pilot Under 30 10 Pilot 31-40 25 Pilot 41-50 20 Pilot Over 50 5
---
title: "Name of job"
output: pdf_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(readxl)
options(scipen = 100)
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE, fig.width=4, fig.height=2.5}
GENDER <- read_xlsx("C:/Users/Desktop/TEST_MARKDOWN.xlsx", sheet=1)
GENDER <- filter(GENDER, JOB == "Analyst")
ggplot(GENDER,aes(y=GENDER, x=PEOPLE))+
geom_bar(stat = 'identity')+
theme_minimal()
```
```{r, echo=FALSE, fig.width=3.7, fig.height=2.5}
AGE <- read_xlsx("C:/Users/Desktop/TEST_MARKDOWN.xlsx", sheet=2)
AGE <- filter(AGE, JOB == "Analyst")
ggplot(AGE,aes(y=AGE, x=PEOPLE))+
geom_bar(stat = 'identity')+
theme_minimal()
```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几个步骤可以实现这一目标。不过,远不远胜于自己创建70个文件!
您有两个不同的数据集。在您的帖子中,一个具有
job
;另一个具有作业
。我将它们都更改为job
。在您的帖子中,作业标题以相同的方式记录。例如-如果这是始终 true,这将起作用。如果并非总是如此,仍然可以做到这一点,但需要修改。
您将创建一个RMD 模板和一个使用该模板的R脚本。我建议您首先为一个工作领域创建RMD。格式化它是您喜欢所有文件的样子。然后将文件修改为模板(或复制)。一旦它是模板,您将无法在没有R文件的情况下编织RMD文件。
YAML具有基于职位的标题,但这仅仅是因为您已经表明这是需要的。但是,呼叫
参数:
具有非常具体的信息。您可以在引号中更改内容,但是参数:
必须保留,并且您要迭代的变量,例如job
,必须完全按原样编写出现在数据中。库和选项(无更改)
块的代码 - 指出删除特定作业和内容
params $ job
。这将来自R文件。保存此RMD文件,但不要打扰编织;它行不通。记下该文件的名称和位置;您需要它的R文件。
我的RMD名为pdfgraphs.rmd(我知道如此原始)。我将R文件保存在与RMD相同的目录中(不过,这不是必需的)。但是,它们没有保存在当前的工作目录中,因此我仍然需要这条路径。
现在,当我运行此代码时, R文件的内容
将创建一个名为“作业名称”的PDF,就像这样。
不需要。 (感谢GD)
There are a few steps to make this happen. Far less than creating the 70 files yourself, though!
You have two different data sets. In your post, one has
Job
; the other hasJOB
. I changed them both toJOB
. In your post, the job titles are documented the same way. For example—If this is always true, this will work. It can still be done if it isn't always true, but it would require modifications.
You'll create an RMD template and an R script that uses that template. I would suggest that you first create the an RMD for one job field. Format it exactly how you like all of the files to look. Then modify the file to be the template (or copy it). Once it's the template, you will not be able to knit the RMD file without the R file.
The YAML has a title based on the job title, but only because you had indicated this was desired. However, the call
params:
has very specific information. You can change the content in the quotes, butparams:
must remain as is, and the variable you're iterating over, likeJOB
here, must be written exactly as it appears in the data.The libraries and options (no changes)
The code for the chunks—note the removal of a specific job and the content
params$JOB
. This is going to come from the R file.Save this RMD file, but don't bother knitting; it won't work. Take note of the name and location of this file; you'll need it for the R file.
My RMD was named pdfGraphs.Rmd (so original, I know). I saved the R file in the same directory as the RMD (this isn't required, though). However, they aren't saved in the current working directory, so I still needed the path.
The contents of the R file
Now when I run this code, it will create a pdf named the name of the JOB, like so.
FYI, I updated this content by removing the library
epoxy
. It's not needed. (Thanks GD)