简体   繁体   English

如何将大频率表拟合到R降价滑坡中?

[英]How to fit large frequency table into R markdown ioslides?

I'm trying to fit large table of frequencies into my slide. 我正在尝试将大型频率表放入幻灯片。 There are many values, and even the rare ones would be nice to show. 有很多价值,即使是稀有价值也很容易显示。

I played with different options but none gives me a satisfactory solution. 我选择了不同的选项,但没有一个能让我满意的解决方案。 Here is Rmd so far: 到目前为止,这里是Rmd

---
title: "Untitled"
author: "author"
date: "date"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
df <- as.data.frame(table(rownames((USArrests))))
```

## table 1

```{r t1, echo = TRUE}
table(rownames((USArrests)))
```

## table 2

```{r t2}
library(knitr)
library(kableExtra)
kable(df, "html") %>%
  kable_styling(bootstrap_options = "striped", font_size = 10)
```

Table 1 doesn't fit: 表1不适合:

在此处输入图片说明

Table 2 could be squeezed but with tiny font, and lots of wasted space on the sides. 表2可以压缩,但字体很小,并且两侧浪费了很多空间。

I also looked into pander , xtable and stargazer but failed to find solution from them either. 我也看了成panderxtablestargazer ,但未能找到任何从他们的解决方案。

Any other alternatives? 还有其他选择吗?

You could spread your table across multiple columns to fit the space. 您可以将表格分布在多列中以适应空间。 In my example below, I split the frame up into 3 pairs of columns with uneven length. 在下面的示例中,我将框架分为3对长度不均匀的列。

---
output: ioslides_presentation
---

```{r setup, include=FALSE}
library(dplyr)
library(magrittr)
library(knitr)
library(kableExtra)
```

## table 1

```{r, echo=TRUE, eval=FALSE}
USArrests %>% rownames %>% table
```

```{r, echo=FALSE}
df <- USArrests %>%
  rownames %>%
  table %>%
  as_tibble

df %$%
  tibble(
    name1 = `.`[1:17],
    n1 = n[1:17],
    name2 = `.`[18:34],
    n2 = n[18:34],
    name3 = c(`.`[35:50], ""),
    n3 = c(n[35:50], "")
  ) %>%
  kable("html", align = c("l", "c"), col.names = rep(c("Name", "Frequency"), 3)) %>%
  kable_styling(bootstrap_options = c("striped", "condensed"), font_size = 18)
```

在此处输入图片说明

NB I accept the transform step into multiple columns could have been done more elegantly and providing and more programmatic solution, however, I'll leave that to others to refine. 注意:我接受将转换步骤转换为多列的操作可以更优雅地完成,并提供更多的程序化解决方案,但是,我会将其留给其他人来完善。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM