gpt4 book ai didi

r - 如何在生成的 PowerPoint 中显示 R 数据框

转载 作者:行者123 更新时间:2023-12-01 12:06:56 25 4
gpt4 key购买 nike

---
title: "Untitled"
output: powerpoint_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Table

```{r table, echo=FALSE, message=FALSE, warning=FALSE}
library(tidyverse)
library(kableExtra)
mtcars %>%
count(cyl) %>%
ungroup() # %>%
# kable() %>%
# kable_styling()
```

我正在处理上面的repro。我想以 kable 或 kableExtra 方式呈现 mtcars 计算的数据框,如下所示:

kableExtra

相反,表格以以下控制台格式输出:
## # A tibble: 3 x 2
## cyl n
## <dbl> <int>
## 1 4 11
## 2 6 7
## 3 8 14

如何使我的 R PowerPoint 表格更漂亮,甚至更好,可在 PowerPoint 中编辑?

最佳答案

您可以使用 flextable包裹。它支持带有 R Markdown 的 powerpoint_presentation 输出。您将在下面找到一个示例:

---
title: "Untitled"
output: powerpoint_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Table

```{r table, echo=FALSE, message=FALSE, warning=FALSE}
library(magrittr)
library(flextable)
mtcars[1:5,1:4] %>%
tibble::rownames_to_column() %>%
flextable() %>%
set_header_labels(rowname = "") %>%
add_header_row(values = c("", "Group 1", "Group 2"),
colwidths = c(1, 2, 2)) %>%
theme_zebra() %>% autofit()
```

关于r - 如何在生成的 PowerPoint 中显示 R 数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55692123/

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