Make flextable with merged row titles according to selected column
Source:R/tables.R
apa_flextable.Rd
Make flextable with merged row titles according to selected column
Usage
apa_flextable(
data,
row_title_column = NULL,
row_title_prefix = "",
row_title_sep = " ",
row_title_align = "center",
row_title_border = list(color = "gray20", style = "solid", width = 1),
col_keys = colnames(data),
cwidth = 0.75,
cheight = 0.25,
separate_headers = TRUE,
apastyle = 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,
auto_format_columns = TRUE,
parameter_formatter = NULL,
...
)
Arguments
- data
data.frame or tibble
- row_title_column
quoted column name to group rows
- row_title_prefix
text to be added to each title
- row_title_sep
separator for prefix
- row_title_align
alignment of row title ("left", "center", "right")
- row_title_border
list of flextable styles
- col_keys
column keys passed to flextable (defaults data column names)
- cwidth
initial cell width in inches
- cheight
initial cell height in inches
- separate_headers
separate header rows (default:
TRUE
)- apastyle
apply
apa_style
function (default:TRUE
)- 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
- auto_format_columns
if true, will attempt to format some columns automatically
- parameter_formatter
an apa_parameter_formatter object
- ...
arguments passed to
apa_style
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
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")
Variable
Mean
SD
Automatic
am
0.33
0.49
gear
3.56
0.86
carb
3.61
1.54
Manual
am
0.50
0.52
gear
3.86
0.53
carb
1.79
1.05