| apa_flextable | R Documentation |
The apa_flextable function performs a number of formatting operations on the data before and after the data are sent to flextable. See Details.
apa_flextable(
data,
row_title_column = NULL,
row_title_align = "left",
row_title_prefix = "",
row_title_sep = " ",
row_title_border = list(color = "gray20", style = "solid", width = 1),
left_column_padding = 20,
col_keys = colnames(data),
cwidth = 0.75,
cheight = 0.25,
header_align_vertical = c("top", "middle", "bottom"),
separate_headers = TRUE,
apa_style = TRUE,
font_family = NULL,
font_size = 12,
text_color = "black",
border_color = "black",
border_width = 0.5,
line_spacing = 2,
horizontal_padding = 3,
table_align = "left",
layout = "autofit",
table_width = 1,
markdown = TRUE,
markdown_header = markdown,
markdown_body = markdown,
no_markdown_columns = NULL,
no_markdown_columns_header = NULL,
no_format_columns = NULL,
auto_format_columns = TRUE,
column_formats = NULL,
pretty_widths = TRUE,
add_breaks_between_spanners = TRUE,
...
)
data |
data.frame or tibble |
row_title_column |
Column name or tidyselect function. column to group rows |
row_title_align |
alignment of row title ("left", "center", "right") |
row_title_prefix |
text to be added to each title |
row_title_sep |
separator for prefix |
row_title_border |
list of flextable styles |
left_column_padding |
Number of points the left column is padded (only relevant when there is a |
col_keys |
column keys passed to flextable (defaults data column names) |
cwidth |
initial cell width in inches |
cheight |
initial cell height in inches |
header_align_vertical |
vertical alignment of headers. Can be "top", "middle", or "bottom" |
separate_headers |
separate header rows (default: |
apa_style |
apply |
font_family |
font family |
font_size |
font size |
text_color |
text color |
border_color |
border color |
border_width |
border width in pixels |
line_spacing |
spacing between lines |
horizontal_padding |
horizontal padding (in pixels) |
table_align |
table alignment ("left", "center", "right") |
layout |
table layout ("autofit", "fixed") |
table_width |
table width (in pixels, 0 for auto) |
markdown |
apply markdown formatting to header and body |
markdown_header |
apply markdown formatting to header |
markdown_body |
apply markdown formatting to body |
no_markdown_columns |
body columns that should not be treated as markdown |
no_markdown_columns_header |
column headers that should not be treated as markdown |
no_format_columns |
Column name or tidyselect function. selected columns are not formatted |
auto_format_columns |
if true, will attempt to format some columns automatically |
column_formats |
a column_formats object |
pretty_widths |
apply |
add_breaks_between_spanners |
add breaks between spanners if TRUE |
... |
arguments passed to |
Roughly speaking, apa_flextable performs these operations by default:
Apply as_grouped_data and restructure row titles, if row_title is specified.
Format data with apa_format_columns if auto_format_columns = TRUE
Separate headers into multiple header rows if separate_headers = TRUE
Apply flextable::flextable
Apply flextable::surround to make borders to separate row groups, if any.
Apply the apa_style function (table formatting and markdown conversion) if apa_style = TRUE
Apply pretty_widths if pretty_widths = TRUE
flextable::flextable
library(dplyr)
library(tidyr)
library(flextable)
mtcars %>%
dplyr::select(vs, am, gear, carb) |>
tidyr::pivot_longer(-vs, names_to = "Variable") |>
dplyr::summarise(Mean = round(mean(value), 2),
SD = round(sd(value), 2),
.by = c(Variable,vs)) |>
dplyr::mutate(vs = factor(vs, levels = 0:1, labels = c("Automatic", "Manual"))) |>
apa_flextable(row_title_column= vs, row_title_align = "center") |>
align(j = 2:3, align = "center")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.