gpt4 book ai didi

r-markdown - 将官员/办公室页面上导入的图像最大化为 Word (docx)

转载 作者:行者123 更新时间:2023-12-02 19:22:58 25 4
gpt4 key购买 nike

我最近尝试使用 officedown创建我的文档的 .docx 报告。在我的文档中,我从项目目录中的 \images 文件夹导入图像。

通常,当我编织文档时,我能够最大化其在页面上的位置。有谁知道如何使用 Officedown 来做到这一点?当我在 RMarkdown 中运行此代码时没有任何问题

这是我使用 Officedown 得到的结果 Here is what I get

这就是我想要的(注意图像占据了整个页面) Here is what I want

我在下面添加了一个代表

---
date: "`r Sys.Date()`"
author:
title: "GitHub Example"
output:
officedown::rdocx_document
---

```{r setup, include=FALSE, echo = FALSE}
pacman::p_load(readxl, dplyr, apastats, officedown, officer, ggplot2, knitr) # load packages

knitr::opts_chunk$set(fig.align = 'center',
fig.cap = TRUE,
fig.pos = 'H',
fig.path = 'images/',
echo = FALSE,
warning = FALSE,
message = FALSE,
include = TRUE,
out.height="100%", out.width="100%",
dpi = 300)

```

```{r}
# Creating a boxplot and saving it in \images directory
plot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_boxplot()
ggsave("images/plot.png",plot, width=11, height=8.5, dpi=300)

```

## Figures

Figure \@ref(fig:boxplot) shows a boxplot that is made within the RMarkdown document.
I want to call in an image saved from a previous R scripts which is saved
in my `\images` directory shown in Figure \@ref(fig:plot). But notice how it
does not take up the whole page.

<!---BLOCK_LANDSCAPE_START--->
```{r fig.cap="A boxplot", fig.id = "boxplot"}
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_boxplot()
```
<!---BLOCK_LANDSCAPE_STOP--->


<!---BLOCK_LANDSCAPE_START--->

```{r fig.id="plot", fig.cap="boxplot imported from images folder", echo=FALSE}
knitr::include_graphics("images/plot.png")
```

<!---BLOCK_LANDSCAPE_STOP--->

最佳答案

您可以使用knitr常用参数fig.widthfig.height(英寸)。


---
date: "`r Sys.Date()`"
author:
title: "GitHub Example"
output:
officedown::rdocx_document
---

```{r setup, include=FALSE, echo = FALSE}
pacman::p_load(readxl, dplyr, apastats, officedown, officer, ggplot2, knitr) # load packages

knitr::opts_chunk$set(fig.align = 'center',
echo = FALSE,
warning = FALSE,
message = FALSE,
dpi = 300)

```

```{r}
plot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_boxplot()
```



<!---BLOCK_LANDSCAPE_START--->
```{r fig.cap="A boxplot", fig.id = "boxplot"}
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_boxplot()
```

```{r fig.width=10, fig.height=5, fig.id="plot", fig.cap="boxplot imported from images folder", echo=FALSE}
plot
```

<!---BLOCK_LANDSCAPE_STOP--->

enter image description here

关于r-markdown - 将官员/办公室页面上导入的图像最大化为 Word (docx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62799018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com