【问题标题】:How to make sjPlot::tab_model() html table to be numbered in a bookdown document如何使 sjPlot::tab_model() html 表在 bookdown 文档中编号
【发布时间】:2019-09-18 23:49:21
【问题描述】:

我想在 bookdown 文档中添加模型中的表格(除了其他表格),以便让所有表格自动编号。使用knitr::kable() 时效果很好。但是我无法使用模型表sjPlot::tab_model 的第一个选项或创建这些表的其他函数(例如stargazer::stargazertexreg::htmlreg)来做到这一点

这是一个简单的 .Rmd 示例:

    ---
    title: "Example"
    output: bookdown::html_document2
    ---

    Bookdown gets numbered tables when using `kable`.

    ```{r tab}
    knitr::kable(head(mtcars),
                   caption = "First table")
    ```

    But I want to make a `tab_model` table to be also automatically numbered in the document

    ```{r lm-tab1}
    reg_mod <- lm(mpg ~ wt, data = mtcars)
    sjPlot::tab_model(reg_mod, title = "Second table")
    ```

    Optionally, I would like to be able to do it with other package for creating automatic model 
    tables, such as `stargazer::stargazer`, `texreg::htmlreg` or perhaps other suggestion

    ```{r lm-tab2, results='asis'}
    stargazer::stargazer(reg_mod, type = "html", title = "Third table")
    ```

    ```{r lm-tab3, results='asis'}
    texreg::htmlreg(reg_mod, caption = "Fourth table")
    ```

知道如何使 tab_model 或回归模型的任何其他函数与 bookdown 编号一起使用吗?

【问题讨论】:

  • 在此处查看 bookdown 文档(靠近底部):bookdown.org/yihui/bookdown/tables.html
  • 我已经看到了,但我不知道如何使用此信息解决上述问题。据我所知,无法使用 tab_model 创建降价输出

标签: r bookdown sjplot


【解决方案1】:

正如documentation 中提到的,如果您在标题/标题中包含(\#tab:my-table-lab) 之类的标签,则 bookdown 支持自动对其他函数生成的表格进行编号。

例如,使用您的 tab_model 表,您可以:

reg_mod <- lm(mpg ~ wt, data = mtcars)
sjPlot::tab_model(reg_mod, title = "(\\#tab:tab-model-table) Second table")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多