knitr::opts_chunk$set(collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE)
sjt.*-functions as well as
tab_model() create a HTML page with the table output. This table, by default, is opened in the viewer pane of your IDE (in case you’re using an IDE that also supports the viewer pane). If a viewer pane is not available, the created HTML output is saved as temporary file and opened in your default web browser. The temporary files are deleted after your R session ends.
You can save the HTML page as file for further usage by specifying the
file-argument The saved HTML file can be opened by word processors like LibreOffice or Microsoft Office.
You can directly drag and drop a table from the RStudio viewer pane or browser into your word processor. Simply select the complete table with your mouse and drag it into office.
The table output is in in HTML format. The table style (visual appearance) is formatted using Cascading Style Sheets (CSS). If you are a bit familiar with these topics, you can easily customize the appearance of the table output.
Many table elements (header, row, column, cell, summary row, first row or column...) have CSS-class attributes, which can be used to change the table style. Since each
sjt.* function as well as
tab_model() has different table elements and thus different class attributes, you first need to know which styles can be customized.
The table functions invisibly return several values. The return value
page.style contains the style information for the HTML table. You can print this style sheet to console using the
library(sjPlot) data(efc) m <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc) tab <- tab_model(m)
The HTML code is in the
page.content return value. The following code prints the HTML code of the table to the R console:
Now you can see which table elements are associated with which CSS class attributes.
You can customize the table output with the
CSS parameter. This parameter requires a list of attributes, which follow a certain pattern:
1) each attributes needs a
2) followed by the class name (e.g.
4) the CSS format (in (single) quotation marks)
5) the CSS format must end with a colon (;)
tab_model( m, CSS = list( css.depvarhead = 'color: red;', css.centeralign = 'text-align: left;', css.firsttablecol = 'font-weight: bold;', css.summary = 'color: blue;' ) )
In the above example, the header row lost the original style and just became red. If you want to keep the original style and just add additional style information, use the plus-sign (+) as initial character for the parameter attributes. In the following example, the header row keeps its original style and is additionally printed in red:
tab_model(m, CSS = list(css.depvarhead = '+color: red;'))
There are a few pre-defined CSS-themes, which can be accessed with the
css_theme()-function. There are more pre-defined themes planned for the future.
tab_model(m, CSS = css_theme("cells"))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.