首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包括一个图形和它的标题,不包括图(rmarkdown,knitr)

包括一个图形和它的标题,不包括图(rmarkdown,knitr)
EN

Stack Overflow用户
提问于 2019-09-24 22:04:43
回答 2查看 125关注 0票数 4

我正在写一篇使用rmarkdownknitrrticles package的论文。这篇论文将提交给PLOS ONE,我正在使用rticles R包中提供的PLOS ONE LaTeX模板。

PLOS ONE要求数字标题以文本形式出现(数字应出现在文本中),而数字应与主手稿分开上传。

因此,我想知道是否有一种方法可以在使用knitr生成的PDF文件中包含图形标题,而不包含绘图?

下面是所需结果的屏幕截图。Overleaf上也提供了LaTeX模板。

EN

回答 2

Stack Overflow用户

发布于 2019-09-25 00:13:01

您可以在LaTeX包caption的帮助下隐藏绘图(最初由@duckmayer建议)并添加标题

代码语言:javascript
复制
---
title: Title of submission to PLOS journal
author:
  - name: Alice Anonymous
    email: alice@example.com
    affiliation: Some Institute of Technology
    corresponding: alice@example.com
address:
  - code: Some Institute of Technology
    address: Department, Street, City, State, Zip
abstract: |
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.

author_summary: |
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.

output: rticles::plos_article
header-includes:
  - \usepackage{caption}
---

# Introduction

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

```{r pressure, echo=FALSE,  fig.show='hide', results='asis', fig.path="plots-"}

绘图(压力)

cat(“\n\captionof{ figure }{这里是一个图形标题。}\n”)

代码语言:javascript
复制

结果:

在本例中,要提交的图形的名称为plots-pressure-1.pdf

票数 2
EN

Stack Overflow用户

发布于 2019-09-24 22:45:21

我只需要使用块选项out.widthout.height将最终输出中的绘图缩小到维度0 x 0。(有关所有块选项,请参阅这个很棒的文档:https://yihui.name/knitr/options/#plots)。

例如:

代码语言:javascript
复制
---
title: "SO Answer"
author: "duckmayr"
date: "9/24/2019"
output: html_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo =真)

代码语言:javascript
复制
Here's how to make the figure with the caption but without the plot:

```{r pressure, fig.cap='Here is a figure caption.', out.width=0, out.height=0}

绘图(压力)

代码语言:javascript
复制

更新:绘图文件在哪里?

如果添加像这样的行

代码语言:javascript
复制
knitr::opts_chunk$set(fig.path = "figures/")

对于上面的setup块,绘图将保存在figures/子目录中。例如,在编织之后

代码语言:javascript
复制
---
title: "SO Answer"
author: "duckmayr"
date: "9/24/2019"
output: html_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo =真)

knitr::opts_chunk$set(fig.path =“图形/”)

代码语言:javascript
复制
Here's how to make the figure with the caption but without the plot:

```{r pressure, fig.cap='Here is a figure caption.', out.width=0, out.height=0}

绘图(压力)

代码语言:javascript
复制

我可以在~/figures/中看到这些文件

代码语言:javascript
复制
[duckmayr@duckmayr-pc ~]$ ls ~/figures/
pressure-1.png

(由于您正在编织为PDF,因此默认情况下,您的绘图图像也将保存为PDF,而不是PNG)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58082093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档