tinytable 使用教程

tinytable 使用教程

tinytableSimple and Customizable Tables in `R`项目地址:https://gitcode.com/gh_mirrors/ti/tinytable

项目介绍

tinytable 是一个小巧但功能强大的 R 包,用于在多种格式(如 HTML、LaTeX、Word、PDF、PNG、Markdown 和 Typst)中绘制美观的表格。用户界面简洁易学,同时提供了强大的框架来创建无限定制的表格。tinytable 默认不导入任何第三方 R 包,保持轻量级。

项目快速启动

安装

tinytable 可以通过 R-Universe 或 CRAN 安装。推荐从 R-Universe 安装以获取最新功能:

install.packages("tinytable", repos = "https://vincentarelbundock.r-universe.dev")

或者从 CRAN 安装:

install.packages("tinytable")

基本使用

加载 tinytable 包并创建一个简单的表格:

library(tinytable)
x <- mtcars[1:5, 1:5]
tt(x)

进阶使用

创建一个更复杂的表格,添加标题、脚注、颜色、样式和跨列标题:

cap <- "A simple \\texttt{tinytable} example"
not <- "Nullam odio est ullamcorper scelerisque lectus a eleifend luctus nisl Etiam ullamcorper nibh vel interdum auctor odio nulla mollis tortor vel fringilla ante quam quis est"
tt(x, caption = cap, notes = not, width = 5) |>
  style_tt(i = 1:3, j = 1:2, background = "teal", color = "white", bold = TRUE) |>
  group_tt(j = list("Halloumi" = 1:2, "Tofu" = 4:5))

应用案例和最佳实践

案例1:学术论文中的表格

在学术论文中,经常需要创建格式严谨的表格。tinytable 可以轻松地将数据框转换为 LaTeX 表格,并进行高度定制:

data <- data.frame(
  Variable = c("Age", "Gender", "Income"),
  Mean = c(34.5, 0.65, 50000),
  SD = c(5.2, 0.12, 10000)
)

tt(data, caption = "Descriptive Statistics", notes = "Data from a survey", format = "latex")

案例2:网页中的交互式表格

在网页中,可以使用 tinytable 创建交互式 HTML 表格,并利用 Bootstrap 框架进行样式定制:

tt(data, format = "html") |>
  style_tt(i = 1, j = 1:3, background = "blue", color = "white", bold = TRUE)

典型生态项目

knitr

knitr 是一个强大的 R 包,用于创建动态报告。tinytable 可以与 knitr 结合使用,生成包含定制表格的报告:

library(knitr)
library(tinytable)

data <- mtcars[1:5, 1:5]
tt(data) |>
  style_tt(i = 1:3, j = 1:2, background = "teal", color = "white", bold = TRUE) |>
  kable()

rmarkdown

rmarkdown 是另一个流行的 R 包,用于创建可重复的研究文档。tinytable 可以与 rmarkdown 结合,生成包含定制表格的文档:

library(rmarkdown)
library(tinytable)

data <- mtcars[1:5, 1:5]
tt(data) |>
  style_tt(i = 1:3, j = 1:2, background = "teal", color = "white", bold = TRUE) |>
  render("report.Rmd")

通过这些生态项目的结合使用,tinytable 可以进一步扩展其功能,满足更多复杂的需求。

tinytableSimple and Customizable Tables in `R`项目地址:https://gitcode.com/gh_mirrors/ti/tinytable

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沈婕嵘Precious

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值