Title: | User-Friendly Tables with Color Helpers for Data Exploration |
---|---|
Description: | Make it easy to deal with multiple cross-tables in data exploration, by creating them, manipulating them, and adding color helpers to highlight important informations (differences from totals, comparisons between lines or columns, contributions to variance, confidence intervals, odds ratios, etc.). All functions are pipe-friendly and render data frames which can be easily manipulated. In the same time, time-taking operations are done with 'data.table' to go faster with big dataframes. Tables can be exported with formats and colors to 'Excel', plot and html. |
Authors: | Brice Nocenti [aut, cre] |
Maintainer: | Brice Nocenti <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.3.0 |
Built: | 2025-02-01 12:33:29 UTC |
Source: | https://github.com/bricenocenti/tabxplor |
subset method for class tabxplor_grouped_tab
"x[i] ; x[i, j, ... , drop = TRUE]"
"x[i] ; x[i, j, ... , drop = TRUE]"
x |
A tabxplor_grouped_tab object. |
i , j , ...
|
Indices |
drop |
For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. |
An object of class tabxplor_grouped_tab
.
set sub-subset method for class tabxplor_grouped_tab
"x[[...]] <- value"
"x[[...]] <- value"
x |
A tabxplor_grouped_tab object. |
... |
Indices |
value |
The new value. |
An object of class tabxplor_grouped_tab
.
set subset method for class tabxplor_grouped_tab
"x[i] <- value ; x[i, j, ...] <- value"
"x[i] <- value ; x[i, j, ...] <- value"
x |
A tabxplor_grouped_tab object. |
i , j , ...
|
Indices. |
value |
The new value. |
An object of class tabxplor_grouped_tab
.
$ method for class tabxplor_fmt
## S3 method for class 'tabxplor_fmt' x$name
## S3 method for class 'tabxplor_fmt' x$name
x |
A tabxplor_fmt object. |
name |
The name of the field to extract. |
The relevant field of the tabxplor_fmt.
arrange method for class tabxplor_tab
## S3 method for class 'tabxplor_tab' arrange( .data, ..., .by_group = TRUE, .by_totals = TRUE, .only_main_display = TRUE, .locale = NULL )
## S3 method for class 'tabxplor_tab' arrange( .data, ..., .by_group = TRUE, .by_totals = TRUE, .only_main_display = TRUE, .locale = NULL )
.data |
A tibble of class tabxplor_tab. |
... |
< |
.by_group |
By default, will sort first by grouping variable.
Set to |
.by_totals |
By default, will put totals at the end of their group.
Set to |
.only_main_display |
By default, only the rows with the same display
than the first row are arranged : if the first row of the group displays
percentages, rows with n or pvalues are kept at the same place
(typically, at the end of the group). Rows with the text |
.locale |
The locale to sort character vectors in. |
A tibble of class tabxplor__tab
or tabxplor_grouped_tab
.
Complete partial total rows
complete_partial_totals(tabs)
complete_partial_totals(tabs)
tabs |
A table or data.framate containting |
The table with completed total rows, total tables, and reference rows.
dplyr_col_modify method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' dplyr_col_modify(data, cols)
## S3 method for class 'tabxplor_grouped_tab' dplyr_col_modify(data, cols)
data |
A data frame. |
cols |
A named list used modify columns. A |
An object of class tabxplor_grouped_tab
.
dplyr_reconstruct method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' dplyr_reconstruct(data, template)
## S3 method for class 'tabxplor_grouped_tab' dplyr_reconstruct(data, template)
data |
A data frame. |
template |
Template to use for restoring attributes |
An object of class tabxplor_grouped_tab
.
dplyr_row_slice method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' dplyr_row_slice(data, i, ...)
## S3 method for class 'tabxplor_grouped_tab' dplyr_row_slice(data, i, ...)
data |
A data frame. |
i |
A numeric or logical vector that indexes the rows of |
... |
Future parameters. |
An object of class tabxplor_grouped_tab
.
fct_recode helper to recode multiple variables
fct_recode_helper( data, .cols = -where(is.numeric), name_in, name_out, style = c("mutate", "base"), reminder = TRUE, cat = TRUE )
fct_recode_helper( data, .cols = -where(is.numeric), name_in, name_out, style = c("mutate", "base"), reminder = TRUE, cat = TRUE )
data |
The data frame. |
.cols |
<tidy-select> The variables to recode. |
name_in |
The name of the input data frame. Default to the expression given in |
name_out |
The name of the output data frame, if different from the input data frame. |
style |
Default is to use |
reminder |
By default, a reminder of the syntax ( |
cat |
By default the result is written in the console if there are less than 6 variables, written in a temporary file and opened otherwise. Set to false to get a data frame with a character variable instead. |
When the number of variables is less than 5, a text in console as a side effect.
With more than 5 variables, a temporary R file. A tibble
with the recode text as a
character variable is returned invisibly (or as main result if cat = TRUE
).
fmt
vectors, of class tabxplor_fmt
, powers tabxplor
and tab
tibbles.
As a record
, they stores all data necessary to
calculate percentages, Chi2 metadata or confidence intervals, but also to format and
color the table to help the user read it. You can access this data with
vctrs::field
, or change it with
vctrs:field<-
. A fmt
vector have 13 fields :
n
, digits
, display
, wn
, pct
, mean
,
diff
, ctr
, var
, ci
, in_totrow
, in_tottab
,
in_refrow
. Other arguments are attributes, attached not to each value, but to
the whole vector, like type
, totcol
or color
. You can get them
with attr
and modify them with
attr<-
. Special functions listed below are made to
facilitate programming with with tabxplor formatted numbers.
taxplfmt
vectors can use all standard operations, like +, -, sum(), or c(),
using vctrs.
fmt( n = integer(), type = "n", digits = rep(0L, length(n)), display = dplyr::case_when(type == "mean" ~ "mean", type %in% c("row", "col", "all", "all_tabs") ~ "pct", TRUE ~ "n"), wn = rep(NA_real_, length(n)), pct = rep(NA_real_, length(n)), mean = rep(NA_real_, length(n)), diff = rep(NA_real_, length(n)), ctr = rep(NA_real_, length(n)), var = rep(NA_real_, length(n)), ci = rep(NA_real_, length(n)), rr = rep(NA_real_, length(n)), or = rep(NA_real_, length(n)), in_totrow = rep(FALSE, length(n)), in_tottab = rep(FALSE, length(n)), in_refrow = rep(FALSE, length(n)), comp_all = NA, ref = "", ci_type = "", col_var = "", totcol = FALSE, refcol = FALSE, color = "" ) is_fmt(x) get_num(x) set_num(x, value) get_type(x, ...) set_type(x, type) is_totrow(x, ...) as_totrow(x, in_totrow = TRUE) is_tottab(x, ...) as_tottab(x, in_tottab = TRUE) set_display(x, value) is_totcol(x, ...) as_totcol(x, totcol = TRUE) is_refrow(x, ...) as_refrow(x, in_refrow = TRUE) get_comp_all(x, replace_na = TRUE) set_comp_all(x, comp_all = FALSE) get_ref_type(x, ...) set_diff_type(x, ref) get_ci_type(x, ...) set_ci_type(x, ci_type) get_col_var(x, ...) set_col_var(x, col_var) is_refcol(x, ...) as_refcol(x, refcol = TRUE) get_color(x, ...) set_color(x, color) get_digits(x) set_digits(x, value)
fmt( n = integer(), type = "n", digits = rep(0L, length(n)), display = dplyr::case_when(type == "mean" ~ "mean", type %in% c("row", "col", "all", "all_tabs") ~ "pct", TRUE ~ "n"), wn = rep(NA_real_, length(n)), pct = rep(NA_real_, length(n)), mean = rep(NA_real_, length(n)), diff = rep(NA_real_, length(n)), ctr = rep(NA_real_, length(n)), var = rep(NA_real_, length(n)), ci = rep(NA_real_, length(n)), rr = rep(NA_real_, length(n)), or = rep(NA_real_, length(n)), in_totrow = rep(FALSE, length(n)), in_tottab = rep(FALSE, length(n)), in_refrow = rep(FALSE, length(n)), comp_all = NA, ref = "", ci_type = "", col_var = "", totcol = FALSE, refcol = FALSE, color = "" ) is_fmt(x) get_num(x) set_num(x, value) get_type(x, ...) set_type(x, type) is_totrow(x, ...) as_totrow(x, in_totrow = TRUE) is_tottab(x, ...) as_tottab(x, in_tottab = TRUE) set_display(x, value) is_totcol(x, ...) as_totcol(x, totcol = TRUE) is_refrow(x, ...) as_refrow(x, in_refrow = TRUE) get_comp_all(x, replace_na = TRUE) set_comp_all(x, comp_all = FALSE) get_ref_type(x, ...) set_diff_type(x, ref) get_ci_type(x, ...) set_ci_type(x, ci_type) get_col_var(x, ...) set_col_var(x, col_var) is_refcol(x, ...) as_refcol(x, refcol = TRUE) get_color(x, ...) set_color(x, color) get_digits(x) set_digits(x, value)
n |
The underlying count, as an integer vector of length |
type |
The type of the column, which defines the type of background calculation to be made (as a single string, since it's not a field but an attribute) :
|
digits |
The number of digits, as an integer, or an integer vector the length
of |
display |
The display type : the name of the field you want to show when printing
the vector. Among |
wn |
The underlying weighted counts, as a double vector the length of
|
pct |
The percentages, as a double vector the length of |
mean |
The means, as a double vector the length of |
diff |
The differences (from totals or first cells),
as a double vector the length of |
ctr |
The contributions of cells to (sub)tables variances,
as a double vector the length of |
var |
The cells variances, as a double vector the length of |
ci |
The confidence intervals, as a double vector the length of |
rr |
The relative risk, as a double vector the length of |
or |
The odds ratio or relative risk ratio, as a double vector the length of |
in_totrow |
|
in_tottab |
|
in_refrow |
|
comp_all |
|
ref |
The type of difference of the vector. Cf. |
ci_type |
The type of confidence intervals of the vector (calculate
with
|
col_var |
The name of the |
totcol |
|
refcol |
|
color |
The type of color to print :
|
x |
The object to test, to get a field in, or to modify. |
value |
The value you want to inject in some |
... |
Used in methods to add arguments in the future. |
replace_na |
By default, |
A vector of class tabxplor_fmt
.
A logical vector.
A double vector.
A modified fmt vector.
A character vector with the vectors type.
A modified fmt vector.
A logical vector with the fmt vectors totrow field.
A modified fmt vector with totrow field changed.
A logical vector with the fmt vectors tottab field.
A modified fmt vector with tottab field changed.
The entered objects, with all fmt vectors with the wanted display.
A logical vector with the fmt vectors totcol attribute.
A modified fmt vector with totcol attribute changed.
A logical vector with the fmt vectors in_refrow field
A modified fmt vector with in_refrom field changed.
A modified fmt vector with comp attribute changed.
A logical vector with the fmt vectors type attributes
A modified fmt vector.
A logical vector with the fmt vectors ci_type attributes
A modified fmt vector.
A logical vector with the fmt vectors col_var attributes
A modified fmt vector.
A logical vector with the fmt vectors is_refcol attributes
A modified fmt vector.
A logical vector with the fmt vectors color attributes
A modified fmt vector.
is_fmt()
: a test function for class fmt.
get_num()
: get the currently displayed field
set_num()
: set the currently displayed field (not changing display type)
get_type()
: get types of fmt columns (at fmt
level or tab
level)
set_type()
: set the column type attribute of a fmt
vector
is_totrow()
: test function to detect cells in total rows
(at fmt
level or tab
level)
as_totrow()
: set the "in_totrow" field (belong to total row)
is_tottab()
: test function to detect cells in total tables
(at fmt
level or tab
level)
as_tottab()
: set the "in_tottab" field (belong to total table)
set_display()
: set the "display" vctrs::field of a fmt
vector, or of
all of them in the whole tibble.
is_totcol()
: test function for total columns
(at fmt
level or tab
level)
as_totcol()
: set the "totcol" attribute of a fmt
vector
is_refrow()
: test function to detect cells in reference rows
(at fmt
level or tab
level)
as_refrow()
: set the "in_refrow" field (belong to reference row)
get_comp_all()
: get comparison level of fmt columns
set_comp_all()
: set the comparison level attribute of a fmt
vector
get_ref_type()
: get differences type of fmt columns (at fmt
level or tab
level)
set_diff_type()
: set the differences type attribute of a fmt
vector
get_ci_type()
: get confidence intervals type of fmt columns (at fmt
level or tab
level)
set_ci_type()
: set the confidence intervals type attribute of a fmt
vector
get_col_var()
: get names of column variable of fmt columns (at fmt
level or tab
level)
set_col_var()
: set the "col_var" attribute of a fmt
vector
is_refcol()
: test function for reference columns (at fmt
level or tab
level)
as_refcol()
: set the "ref_col" attribute of a fmt
vector
get_color()
: get color (at fmt
level or tab
level)
set_color()
: set the "color" attribute of a fmt
vector
get_digits()
: get the "digits" field
set_digits()
: set the "digits" field
library(dplyr) f <- fmt(n = c(7, 19, 2), type = "row", pct = c(0.25, 0.679, 0.07)) f # To get the currently displayed field : get_num(f) # To modify the currently displayed field : set_num(f, c(1, 0, 0)) # See all the underlying fields of a fmt vector (a data frame with a number of rows # equal to the length of the vector) : vctrs::vec_data(f) # To get the numbers of digits : vctrs::field(f, "digits") f$digits # To get the count : vctrs::field(f, "n") f$n # To get the display : vctrs::field(f, "display") f$display # To modify a field, you can use `dplyr::mutate` on the fmt vector, # referring to the names of the columns of the underlying data.frame (`vctrs::vec_data`) : vctrs::`field<-`(f, "pct", c(1, 0, 0)) mutate(f, pct = c(1, 0, 0)) # See all the attributes of a fmt vector : attributes(f) # To modify the "type" attribute of a fmt vector : set_type(f, "col") # To modify the "color" attribute of a fmt vector : set_color(f, "contrib") tabs <- tab(starwars, sex, hair_color, gender, na = "drop", pct = "row", other_if_less_than = 5) # To identify the total columns, and work with them : is_totcol(tabs) tabs %>% mutate(across(where(is_totcol), ~ "total column")) # To identify the total rows, and work with them : is_totrow(tabs) tabs %>% mutate(across( where(is_fmt), ~ if_else(is_totrow(.), true = "into_total_row", false = "normal_cell") )) # To identify the total tables, and work with them : tottabs <- is_tottab(tabs) tabs %>% tibble::add_column(tottabs) %>% mutate(total = if_else(tottabs, "part of a total table", "normal cell")) # To access the displayed numbers, as numeric vectors : tabs %>% mutate(across(where(is_fmt), get_num)) # To access the displayed numbers, as character vectors (without colors) : tabs %>% mutate(across(where(is_fmt), format)) # To access the (non-displayed) differences of the cells percentages from totals : tabs %>% mutate(across(where(is_fmt), ~ vctrs::field(., "diff"))) # To do more complex operations, like creating a new column with standard deviation and # print it with 2 decimals, use `dplyr::mutate` on all the fmt columns of a table : tab_num(forcats::gss_cat, race, c(age, tvhours), marital, digits = 1L, comp = "all") |> dplyr::mutate(dplyr::across( #Mutate over the whole table. c(age, tvhours), ~ dplyr::mutate(., #Mutate over each fmt vector's underlying data.frame. var = sqrt(var), display = "var", digits = 2L) |> set_color("no"), .names = "{.col}_sd" ))
library(dplyr) f <- fmt(n = c(7, 19, 2), type = "row", pct = c(0.25, 0.679, 0.07)) f # To get the currently displayed field : get_num(f) # To modify the currently displayed field : set_num(f, c(1, 0, 0)) # See all the underlying fields of a fmt vector (a data frame with a number of rows # equal to the length of the vector) : vctrs::vec_data(f) # To get the numbers of digits : vctrs::field(f, "digits") f$digits # To get the count : vctrs::field(f, "n") f$n # To get the display : vctrs::field(f, "display") f$display # To modify a field, you can use `dplyr::mutate` on the fmt vector, # referring to the names of the columns of the underlying data.frame (`vctrs::vec_data`) : vctrs::`field<-`(f, "pct", c(1, 0, 0)) mutate(f, pct = c(1, 0, 0)) # See all the attributes of a fmt vector : attributes(f) # To modify the "type" attribute of a fmt vector : set_type(f, "col") # To modify the "color" attribute of a fmt vector : set_color(f, "contrib") tabs <- tab(starwars, sex, hair_color, gender, na = "drop", pct = "row", other_if_less_than = 5) # To identify the total columns, and work with them : is_totcol(tabs) tabs %>% mutate(across(where(is_totcol), ~ "total column")) # To identify the total rows, and work with them : is_totrow(tabs) tabs %>% mutate(across( where(is_fmt), ~ if_else(is_totrow(.), true = "into_total_row", false = "normal_cell") )) # To identify the total tables, and work with them : tottabs <- is_tottab(tabs) tabs %>% tibble::add_column(tottabs) %>% mutate(total = if_else(tottabs, "part of a total table", "normal cell")) # To access the displayed numbers, as numeric vectors : tabs %>% mutate(across(where(is_fmt), get_num)) # To access the displayed numbers, as character vectors (without colors) : tabs %>% mutate(across(where(is_fmt), format)) # To access the (non-displayed) differences of the cells percentages from totals : tabs %>% mutate(across(where(is_fmt), ~ vctrs::field(., "diff"))) # To do more complex operations, like creating a new column with standard deviation and # print it with 2 decimals, use `dplyr::mutate` on all the fmt columns of a table : tab_num(forcats::gss_cat, race, c(age, tvhours), marital, digits = 1L, comp = "all") |> dplyr::mutate(dplyr::across( #Mutate over the whole table. c(age, tvhours), ~ dplyr::mutate(., #Mutate over each fmt vector's underlying data.frame. var = sqrt(var), display = "var", digits = 2L) |> set_color("no"), .names = "{.col}_sd" ))
Get HTML Color Code of a fmt vector
fmt_get_color_code(x, type = "text", theme = "light", html_24_bit = NULL)
fmt_get_color_code(x, type = "text", theme = "light", html_24_bit = NULL)
x |
The fmt vector to get the html color codes from. |
type |
The style type in |
theme |
For |
html_24_bit |
Use 24bits colors palettes for html tables : set to |
A character vector with html color codes, of the length of the initial vector.
tabs <- tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") dplyr::mutate(tabs, across(where(is_fmt), fmt_get_color_code))
tabs <- tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") dplyr::mutate(tabs, across(where(is_fmt), fmt_get_color_code))
Print method for class tabxplor_fmt
## S3 method for class 'tabxplor_fmt' format(x, ..., html = FALSE, na = NA, special_formatting = FALSE)
## S3 method for class 'tabxplor_fmt' format(x, ..., html = FALSE, na = NA, special_formatting = FALSE)
x |
A fmt object. |
... |
Other parameters. |
html |
Should html tags be added (to print confidence intervals as subscripts) ? |
na |
How |
special_formatting |
Set to |
The fmt printed in a character vector.
Get confidence intervals type of fmt columns
## S3 method for class 'data.frame' get_ci_type(x, ...)
## S3 method for class 'data.frame' get_ci_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the ci_type attributes.
Get confidence intervals type of fmt columns
## Default S3 method: get_ci_type(x, ...)
## Default S3 method: get_ci_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ci_type attribute.
Get confidence intervals type of fmt columns
## S3 method for class 'tabxplor_fmt' get_ci_type(x, ...)
## S3 method for class 'tabxplor_fmt' get_ci_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ci_type attribute.
Get names of column variable of fmt columns
## S3 method for class 'data.frame' get_col_var(x, ...)
## S3 method for class 'data.frame' get_col_var(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the col_var attributes.
Get names of column variable of fmt columns
## Default S3 method: get_col_var(x, ...)
## Default S3 method: get_col_var(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the col_var attribute.
Get names of column variable of fmt columns
## S3 method for class 'tabxplor_fmt' get_col_var(x, ...)
## S3 method for class 'tabxplor_fmt' get_col_var(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the col_var attribute.
Get color
## S3 method for class 'data.frame' get_color(x, ...)
## S3 method for class 'data.frame' get_color(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the color attributes.
Get color
## Default S3 method: get_color(x, ...)
## Default S3 method: get_color(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the color attribute.
Get color
## S3 method for class 'tabxplor_fmt' get_color(x, ...)
## S3 method for class 'tabxplor_fmt' get_color(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the color attribute.
Get differences type of fmt columns
## S3 method for class 'data.frame' get_ref_type(x, ...)
## S3 method for class 'data.frame' get_ref_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the ref attribute.
Get differences type of fmt columns
## Default S3 method: get_ref_type(x, ...)
## Default S3 method: get_ref_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ref attribute.
Get differences type of fmt columns
## S3 method for class 'tabxplor_fmt' get_ref_type(x, ...)
## S3 method for class 'tabxplor_fmt' get_ref_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ref attribute.
Get types of fmt columns
## S3 method for class 'data.frame' get_type(x, ...)
## S3 method for class 'data.frame' get_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the data.frame column's types.
Get types of fmt columns
## Default S3 method: get_type(x, ...)
## Default S3 method: get_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
An empty character vector.
Get types of fmt columns
## S3 method for class 'tabxplor_fmt' get_type(x, ...)
## S3 method for class 'tabxplor_fmt' get_type(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single string with the vector's type.
group_by method for class tabxplor_tab
## S3 method for class 'tabxplor_tab' group_by(.data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data))
## S3 method for class 'tabxplor_tab' group_by(.data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data))
.data |
A tibble of class |
... |
Variables or computations to group by. |
.add |
When |
.drop |
Drop groups formed by factor levels that don't appear in the
data? The default is |
A tibble of class tabxplor_grouped_tab
.
Test function for reference columns
## S3 method for class 'data.frame' is_refcol(x, ...)
## S3 method for class 'data.frame' is_refcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A character vector with the ref_col attributes.
Test function for reference columns
## Default S3 method: is_refcol(x, ...)
## Default S3 method: is_refcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ref_col attribute.
Test function for reference columns
## S3 method for class 'tabxplor_fmt' is_refcol(x, ...)
## S3 method for class 'tabxplor_fmt' is_refcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single character with the ref_col attribute.
Test function to detect cells in reference rows
## S3 method for class 'data.frame' is_refrow(x, ..., partial = TRUE)
## S3 method for class 'data.frame' is_refrow(x, ..., partial = TRUE)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
partial |
Should partial reference rows be counted as reference rows ? Default to FALSE. |
A list of logical vectors with the in_refrow fields.
Test function to detect cells in reference rows
## Default S3 method: is_refrow(x, ...)
## Default S3 method: is_refrow(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with FALSE, the length of x.
Test function to detect cells in reference rows
## S3 method for class 'tabxplor_fmt' is_refrow(x, ...)
## S3 method for class 'tabxplor_fmt' is_refrow(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with the in_refrow field.
Test function for total columns
## S3 method for class 'data.frame' is_totcol(x, ...)
## S3 method for class 'data.frame' is_totcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector, with the data.frame column's totcol attributes.
Test function for total columns
## Default S3 method: is_totcol(x, ...)
## Default S3 method: is_totcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single logical vector with the totcol attribute
Test function for total columns
## S3 method for class 'tabxplor_fmt' is_totcol(x, ...)
## S3 method for class 'tabxplor_fmt' is_totcol(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A single logical vector with the totcol attribute
Test function to detect cells in total rows
## S3 method for class 'data.frame' is_totrow(x, ..., partial = FALSE)
## S3 method for class 'data.frame' is_totrow(x, ..., partial = FALSE)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
partial |
Should partial total rows be counted as total rows ? Default to FALSE. |
A list of logical vectors, with the data.frame column's totrow fields.
Test function to detect cells in total rows
## Default S3 method: is_totrow(x, ...)
## Default S3 method: is_totrow(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with FALSE
.
Test function to detect cells in total rows
## S3 method for class 'tabxplor_fmt' is_totrow(x, ...)
## S3 method for class 'tabxplor_fmt' is_totrow(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with the totrow field.
Test function to detect cells in total tables
## S3 method for class 'data.frame' is_tottab(x, ..., partial = FALSE)
## S3 method for class 'data.frame' is_tottab(x, ..., partial = FALSE)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
partial |
Should partial total tabs be counted as total tabs ? Default to FALSE. |
A list of logical vectors, with the data.frame column's tottab fields.
Test function to detect cells in total tables
## Default S3 method: is_tottab(x, ...)
## Default S3 method: is_tottab(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with FALSE
.
Test function to detect cells in total tables
## S3 method for class 'tabxplor_fmt' is_tottab(x, ...)
## S3 method for class 'tabxplor_fmt' is_tottab(x, ...)
x |
The object to test, to get a field in, or to modify. |
... |
Used in methods to add arguments in the future. |
A logical vector with the tottab field.
Crosstables
jmvtab( data, row_vars = NULL, col_vars = NULL, tab_vars = NULL, wt = NULL, pct = "no", color = "no", chi2 = TRUE, OR = "no", na = "keep", lvs = "all", other_if_less_than = 0, cleannames = TRUE, ref = "auto", ref2 = "first", comp = "tab", ci = "auto", conf_level = 0.95, ci_print = "ci", totaltab = "line", wrap_rows = 35, wrap_cols = 15, display = "auto", add_n = TRUE, add_pct = FALSE, subtext = "", digits = 0 )
jmvtab( data, row_vars = NULL, col_vars = NULL, tab_vars = NULL, wt = NULL, pct = "no", color = "no", chi2 = TRUE, OR = "no", na = "keep", lvs = "all", other_if_less_than = 0, cleannames = TRUE, ref = "auto", ref2 = "first", comp = "tab", ci = "auto", conf_level = 0.95, ci_print = "ci", totaltab = "line", wrap_rows = 35, wrap_cols = 15, display = "auto", add_n = TRUE, add_pct = FALSE, subtext = "", digits = 0 )
data |
A data.frame. |
row_vars |
The row variable, which will be printed with one level per line. If numeric, it will be converted to factor. |
col_vars |
One column is printed for each level of each column variable. For numeric variables means are calculated, in a single column. |
tab_vars |
One subtable is made for each combination of levels of the tab variables. All tab variables are converted to factor. Leave empty to make a simple table. |
wt |
A weight variable, of class numeric. Leave empty for unweighted results. |
pct |
The type of percentages to calculate :
|
color |
The type of colors to print, as a single string. Vectorised
over
|
chi2 |
Set to |
OR |
With
|
na |
The policy to adopt with missing values. It must be a single string.
|
lvs |
The levels of
|
other_if_less_than |
When set to a positive integer, levels with less count than that will be merged into an "Others" level. |
cleannames |
By default, clean levels names, by removing prefix
numbers like "1-", and text in parenthesis. Set to |
ref |
The reference cell to calculate differences and ratios (used
to print
|
ref2 |
A second reference cell is needed to calculate odds ratios (or
relative risks ratios). The first cell of the row or column is used by
default. See |
comp |
The comparison level : by subtables/groups, or for the whole table. |
ci |
The type of confidence intervals to calculate, passed to
By default,
for percentages, with |
conf_level |
The confidence level, as a single numeric between 0 and
|
ci_print |
By default confidence interval are printed with the interval display. Set to "moe" to use pct +- moe instead. |
totaltab |
The total table, if there are subtables/groups (i.e. when
|
wrap_rows |
By default, rownames are wrapped when larger than 30 characters. |
wrap_cols |
By default, colnames are wrapped when larger than 12 characters. |
display |
The information to display in the table. |
add_n |
For |
add_pct |
Set to |
subtext |
A character vector to print rows of legend under the table. |
digits |
The number of digits to print, as a single integer, or an
integer vector the same length as |
A results object containing:
results$html_table |
a html | ||||
results$chi2_table |
a table | ||||
results$plot |
an image | ||||
Tables can be converted to data frames with asDF
or as.data.frame
. For example:
results$chi2_table$asDF
as.data.frame(results$chi2_table)
Print a tabxplor table in html
kable_tabxplor_style( tabs, caption = knitr::opts_current$get("tab.cap"), theme = c("light", "dark"), total_in_bold = TRUE, all_column_borders = FALSE, html_font = NULL, full_width = FALSE, wrap_rows = 35, wrap_cols = 15, whitespace_only = TRUE, subtext = "", ... )
kable_tabxplor_style( tabs, caption = knitr::opts_current$get("tab.cap"), theme = c("light", "dark"), total_in_bold = TRUE, all_column_borders = FALSE, html_font = NULL, full_width = FALSE, wrap_rows = 35, wrap_cols = 15, whitespace_only = TRUE, subtext = "", ... )
tabs |
A data.frame. |
caption |
The table caption. For formatting, you need to use a |
theme |
By default, a white table with black text, Set to |
total_in_bold |
Should rows and cols with "Total" string be set in bold ? |
all_column_borders |
Put a vertical border around each column ? |
html_font |
A string for HTML css font. By default, it uses
|
full_width |
A TRUE or FALSE variable controlling whether the HTML table should have the preferable format for full_width. If not specified, a HTML table will have full width by default but this option will be set to FALSE for a LaTeX table. |
wrap_rows |
By default, rownames are wrapped when larger than 30 characters. |
wrap_cols |
By default, colnames are wrapped when larger than 12 characters. |
whitespace_only |
Set to |
subtext |
A character vector to print rows of legend under the table. |
... |
Other arguments to pass to |
A html table (opened in the viewer in RStudio). Differences from totals, confidence intervals, contribution to variance, and unweighted counts, are available in an html tooltip at cells hover.
tabs <- tibble::tibble(nm = c("First", "Second", "Total"), column1 = c(1, 2, 3), column2 = c(4, 5, 6) ) kable_tabxplor_style(tabs)
tabs <- tibble::tibble(nm = c("First", "Second", "Total"), column1 = c(1, 2, 3), column2 = c(4, 5, 6) ) kable_tabxplor_style(tabs)
mutate method to access vctrs::fields of tabxplor_fmt vectors
## S3 method for class 'tabxplor_fmt' mutate(.data, ...)
## S3 method for class 'tabxplor_fmt' mutate(.data, ...)
.data |
A tabxplor_fmt column. |
... |
Name-value pairs. The name gives the name of the column in the output (do not change it). The value can be:
|
An object of class tabxplor_fmt
.
A constructor for class tabxplor_tab
new_tab( tabs = tibble::tibble(), subtext = "", chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells = integer(), variance = double(), count = integer()), ..., class = character() ) new_grouped_tab( tabs = tibble::tibble(), groups, subtext = "", chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells = integer(), variance = double(), count = integer()), ..., class = character() )
new_tab( tabs = tibble::tibble(), subtext = "", chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells = integer(), variance = double(), count = integer()), ..., class = character() ) new_grouped_tab( tabs = tibble::tibble(), groups, subtext = "", chi2 = tibble::tibble(tables = character(), pvalue = double(), df = integer(), cells = integer(), variance = double(), count = integer()), ..., class = character() )
tabs |
A table, stored into a |
subtext |
A character vector to print legend lines under the table. |
chi2 |
A tibble storing information about pvalues and variances, to fill with
|
... |
Needed to implement subclasses. |
class |
Needed to implement subclasses. |
groups |
The grouping data. |
A tibble
of class tabxplor_tab
.
A tibble
of class tabxplor_grouped_tab
.
Print Chi2 tables columns
## S3 method for class 'tab_chi2_fmt' pillar_shaft(x, ...)
## S3 method for class 'tab_chi2_fmt' pillar_shaft(x, ...)
x |
A fmt object. |
... |
Other parameter. |
A Chi2 table column printed in a pillar.
tibble
columnPillar_shaft method to print class fmt in a tibble
column
## S3 method for class 'tabxplor_fmt' pillar_shaft(x, ...)
## S3 method for class 'tabxplor_fmt' pillar_shaft(x, ...)
x |
A fmt object. |
... |
Other parameter. |
A fmt printed in a pillar.
Printing method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' print( x, width = NULL, ..., n = 100, max_extra_cols = NULL, max_footer_lines = NULL, min_row_var = 30, get_text = FALSE )
## S3 method for class 'tabxplor_grouped_tab' print( x, width = NULL, ..., n = 100, max_extra_cols = NULL, max_footer_lines = NULL, min_row_var = 30, get_text = FALSE )
x |
Object to format or print. |
width |
Width of text output to generate. |
... |
Passed on to |
n |
Number of rows to show. |
max_extra_cols |
Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble. |
max_footer_lines |
Maximum number of footer lines. |
min_row_var |
Minimum number of characters for the row variable. Default to 30. |
get_text |
Set to |
A printed grouped table.
Printing method for class tabxplor_tab
## S3 method for class 'tabxplor_tab' print( x, width = NULL, ..., n = 100, max_extra_cols = NULL, max_footer_lines = NULL, min_row_var = 30, get_text = FALSE )
## S3 method for class 'tabxplor_tab' print( x, width = NULL, ..., n = 100, max_extra_cols = NULL, max_footer_lines = NULL, min_row_var = 30, get_text = FALSE )
x |
Object to format or print. |
width |
Width of text output to generate. |
... |
Passed on to |
n |
Number of rows to show. |
max_extra_cols |
Number of extra columns to print abbreviated information for, if the width is too small for the entire tibble. |
max_footer_lines |
Maximum number of footer lines. |
min_row_var |
Minimum number of characters for the row variable. Default to 30. |
get_text |
Set to |
A printed table.
relocate method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' relocate(.data, ...)
## S3 method for class 'tabxplor_grouped_tab' relocate(.data, ...)
.data |
A tibble of class |
... |
Columns to move. will move columns to the left-hand side; specifying both is an error. |
An object of class tabxplor_grouped_tab
.
rename_with method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' rename_with(.data, .fn, .cols = dplyr::everything(), ...)
## S3 method for class 'tabxplor_grouped_tab' rename_with(.data, .fn, .cols = dplyr::everything(), ...)
.data |
A tibble of class |
.fn |
A function used to transform the selected |
.cols |
Columns to rename; defaults to all columns. |
... |
Additional arguments passed onto |
An object of class tabxplor_grouped_tab
.
rename method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' rename(.data, ...)
## S3 method for class 'tabxplor_grouped_tab' rename(.data, ...)
.data |
A tibble of class |
... |
Use |
An object of class tabxplor_grouped_tab
.
rowwise method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' rowwise(data, ...)
## S3 method for class 'tabxplor_grouped_tab' rowwise(data, ...)
data |
A tibble of class |
... |
Variables to be preserved when calling summarise(). This is typically a set of variables whose combination uniquely identify each row. |
An object of class tabxplor_grouped_tab
and rowwise_df
.
rowwise method for class tabxplor_tab
## S3 method for class 'tabxplor_tab' rowwise(data, ...)
## S3 method for class 'tabxplor_tab' rowwise(data, ...)
data |
A tibble of class |
... |
Variables to be preserved
when calling |
A tibble of class tabxplor_grouped_tab
and rowwise_df
.
Create a score variable from factors
score_from_lv1(data, name, vars_list)
score_from_lv1(data, name, vars_list)
data |
A data.frame. |
name |
The name of the variable to create. |
vars_list |
The list of the factors to count (only the first level is counted, as 1) ; as a character vector. |
The data.frame, with a new variable.
data <- tibble::tibble(group = factor(c("G1", "G1", "G2", "G2", "G3", "G3")), a = factor(c("Oui", "Oui", "Oui", "Oui", "Non", "Oui")), b = factor(c("Oui", "Non", "Non", "Oui", "Non", "Oui")), c = factor(c("Oui", "Oui", "Non", "Non", "Oui", "Oui"))) data |> score_from_lv1("score", vars_list = c("a", "b", "c")) |> tab(group, score, digits = 1)
data <- tibble::tibble(group = factor(c("G1", "G1", "G2", "G2", "G3", "G3")), a = factor(c("Oui", "Oui", "Oui", "Oui", "Non", "Oui")), b = factor(c("Oui", "Non", "Non", "Oui", "Non", "Oui")), c = factor(c("Oui", "Oui", "Non", "Non", "Oui", "Oui"))) data |> score_from_lv1("score", vars_list = c("a", "b", "c")) |> tab(group, score, digits = 1)
select method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' select(.data, ...)
## S3 method for class 'tabxplor_grouped_tab' select(.data, ...)
.data |
A tibble of class |
... |
One or more unquoted expressions separated by commas. Variable names can be
used as if they were positions in the data frame, so expressions like |
An object of class tabxplor_grouped_tab
.
fmt
vector.Set the "display" vctrs::field of a fmt
vector.
## S3 method for class 'data.frame' set_display(x, value)
## S3 method for class 'data.frame' set_display(x, value)
x |
The object to test, to get a field in, or to modify. |
value |
The value you want to inject in some |
The entered objects, with all fmt vectors with the wanted display.
fmt
vector.Set the "display" vctrs::field of a fmt
vector.
## Default S3 method: set_display(x, value)
## Default S3 method: set_display(x, value)
x |
The object to test, to get a field in, or to modify. |
value |
The value you want to inject in some |
The entered vector (nothing happens).
fmt
vector.Set the "display" vctrs::field of a fmt
vector.
## S3 method for class 'tabxplor_fmt' set_display(x, value)
## S3 method for class 'tabxplor_fmt' set_display(x, value)
x |
The object to test, to get a field in, or to modify. |
value |
The value you want to inject in some |
A fmt vectors with the wanted display.
summarise method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' summarise(.data, ..., .groups = NULL)
## S3 method for class 'tabxplor_grouped_tab' summarise(.data, ..., .groups = NULL)
.data |
A tibble of class |
... |
Name-value pairs of summary functions. The name will be the name of the variable in the result. |
.groups |
Grouping structure of the result. |
An object of class tabxplor_grouped_tab
.
A full-featured function to create, manipulate and format single
cross-tables, using colors to make the printed tab more easily readable
(in R terminal or exported to Excel with tab_xl
).
Since objects of class tabxplor_tab
are also of class tibble
, you can then use all
dplyr verbs to modify the result, like select
,
like arrange
, filter
or mutate
.
Wrapper around the more powerful tab_many
.
tab( data, row_var, col_var, tab_vars, wt, sup_cols, pct = "no", color = "no", OR = "no", chi2 = FALSE, na = "keep", cleannames = NULL, other_if_less_than = 0, other_level = "Others", ref = "auto", ref2 = "first", comp = "tab", ci = "no", conf_level = 0.95, totaltab = "line", totaltab_name = "Ensemble", tot = c("row", "col"), total_names = "Total", add_n = TRUE, add_pct = FALSE, subtext = "", digits = 0, filter )
tab( data, row_var, col_var, tab_vars, wt, sup_cols, pct = "no", color = "no", OR = "no", chi2 = FALSE, na = "keep", cleannames = NULL, other_if_less_than = 0, other_level = "Others", ref = "auto", ref2 = "first", comp = "tab", ci = "no", conf_level = 0.95, totaltab = "line", totaltab_name = "Ensemble", tot = c("row", "col"), total_names = "Total", add_n = TRUE, add_pct = FALSE, subtext = "", digits = 0, filter )
data |
A data frame. |
row_var , col_var
|
The row variable, which will be printed with one level per line, and the column variable, which will be printed with one level per column. For numeric variables means are calculated, in a single column. |
tab_vars |
<tidy-select> Tab variables :
a subtable is made for each combination of levels of the selected variables.
Leave empty to make a simple cross-table. All |
wt |
A weight variable, of class numeric. Leave empty for unweighted results. |
sup_cols |
<tidy-select>
Supplementary columns variables, with only the first level printed, and row percentages
(for numeric variables, a mean will be calculated for each |
pct |
The type of percentages to calculate :
|
color |
The type of colors to print, as a single string :
|
OR |
With
|
chi2 |
Set to |
na |
The policy to adopt for missing values, as a single string :
|
cleannames |
Set to |
other_if_less_than |
When set to a positive integer, levels with less count than it will be merged into an "Others" level. |
other_level |
The name of the "Other" level, as a single string. |
ref |
The reference cell to calculate differences and ratios
(used to print
|
ref2 |
A second reference cell is needed to calculate odds ratios
(or relative risks ratios). The first cell of the row or column is used by default.
See |
comp |
The comparison level : by subtables/groups, or for the whole table.
|
ci |
The type of confidence intervals to calculate, passed to
By default, for percentages, with Wilson's method is used,
and with |
conf_level |
The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%). |
totaltab |
The total table, if there are subtables/groups
(i.e. when
|
totaltab_name |
The name of the total table, as a single string. |
tot |
The totals :
|
total_names |
The names of the totals, as a character vector of length one or two.
Use syntax of type |
add_n |
For |
add_pct |
Set to |
subtext |
A character vector to print rows of legend under the table. |
digits |
The number of digits to print, as a single integer. To print a different
number of digits for each |
filter |
A |
A tibble
of class tab
, possibly with colored reading helpers.
All non-text columns are of class fmt
, storing all
the data necessary to print formats and colors. Columns with row_var
and
tab_vars
are of class factor
: every added factor
will be
considered as a tab_vars
and used for grouping. To add text columns without
using them in calculations, be sure they are of class character
.
# A simple cross-table: tab(forcats::gss_cat, marital, race) # With more variables provided, `tab` makes a subtables for each combination of levels: tab(forcats::gss_cat, marital, tab_vars = c(year, race)) # You can also add supplementary columns, text or numeric: tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind")) # Colors to help the user read the table: data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2006, 2012), !marital %in% c("No answer", "Widowed")) gss <- "Source: General social survey 2000-2014" gss2 <- "Source: General social survey 2000, 2006 and 2012" # Differences between the cell and it's subtable's total cell: tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff") # Differences between the cell and the whole table's general total cell: tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff", comp = "all") # Historical differences: data2 <- data %>% dplyr::mutate(year = as.factor(year)) tab(data2, year, marital, race, subtext = gss2, pct = "row", color = "diff", ref = "first", tot = "col") # Differences with the total, except if their confidences intervals are superior to them: tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "diff_ci") # Same differences, minus their confidence intervals: tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "after_ci") # Contribution of cells to table's variance, like in a correspondence analysis: tab(forcats::gss_cat, race, marital, subtext = gss, color = "contrib") # Since the result is a tibble, you can use all dplyr verbs to modify it : library(dplyr) tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind")) %>% dplyr::filter(category != "-1") %>% dplyr::select(-`tropical depression`) %>% dplyr::arrange(is_totrow(.), desc(category)) # With `dplyr::arrange`, don't forget to keep the order of tab variables and total rows: tab(data, race, marital, year, pct = "row") %>% dplyr::arrange(year, is_totrow(.), desc(Married))
# A simple cross-table: tab(forcats::gss_cat, marital, race) # With more variables provided, `tab` makes a subtables for each combination of levels: tab(forcats::gss_cat, marital, tab_vars = c(year, race)) # You can also add supplementary columns, text or numeric: tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind")) # Colors to help the user read the table: data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2006, 2012), !marital %in% c("No answer", "Widowed")) gss <- "Source: General social survey 2000-2014" gss2 <- "Source: General social survey 2000, 2006 and 2012" # Differences between the cell and it's subtable's total cell: tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff") # Differences between the cell and the whole table's general total cell: tab(data, race, marital, year, subtext = gss2, pct = "row", color = "diff", comp = "all") # Historical differences: data2 <- data %>% dplyr::mutate(year = as.factor(year)) tab(data2, year, marital, race, subtext = gss2, pct = "row", color = "diff", ref = "first", tot = "col") # Differences with the total, except if their confidences intervals are superior to them: tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "diff_ci") # Same differences, minus their confidence intervals: tab(forcats::gss_cat, race, marital, subtext = gss, pct = "row", color = "after_ci") # Contribution of cells to table's variance, like in a correspondence analysis: tab(forcats::gss_cat, race, marital, subtext = gss, color = "contrib") # Since the result is a tibble, you can use all dplyr verbs to modify it : library(dplyr) tab(dplyr::storms, category, status, sup_cols = c("pressure", "wind")) %>% dplyr::filter(category != "-1") %>% dplyr::select(-`tropical depression`) %>% dplyr::arrange(is_totrow(.), desc(category)) # With `dplyr::arrange`, don't forget to keep the order of tab variables and total rows: tab(data, race, marital, year, pct = "row") %>% dplyr::arrange(year, is_totrow(.), desc(Married))
tab
Add Chi2 summaries to a tab
tab_chi2( tabs, calc = c("ctr", "p", "var", "counts"), comp = NULL, color = c("no", "auto", "all", "all_pct") )
tab_chi2( tabs, calc = c("ctr", "p", "var", "counts"), comp = NULL, color = c("no", "auto", "all", "all_pct") )
tabs |
|
calc |
By default all elements of the Chi2 summary are calculated :
contributions to variance, pvalue, variance and unweighted count. You can choose which
are computed by selecting elements in the vector |
comp |
Comparison level. When |
color |
The type of colors to print, as a single string.
|
A tibble
of class tab
, with Chi2 summaries as metadata,
possibly colored based on contributions of cells to variance.
tab
Add confidence intervals to a tab
tab_ci( tabs, ci = "auto", comp = NULL, conf_level = 0.95, color = "no", visible = FALSE, method_cell = "wilson", method_diff = "ac" )
tab_ci( tabs, ci = "auto", comp = NULL, conf_level = 0.95, color = "no", visible = FALSE, method_cell = "wilson", method_diff = "ac" )
tabs |
|
ci |
The type of ci to calculate. Set to "cell" to calculate absolute confidence
intervals. Set to "diff" to calculate the confidence intervals of the difference
between a cell and the relative total cell (or the reference cell,
when |
comp |
Comparison level. When |
conf_level |
The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%). |
color |
The type of colors to print, as a single string.
|
visible |
By default confidence intervals are calculated and used to set colors,
but not printed. Set to |
method_cell |
Character string specifying which method to use with percentages
for |
method_diff |
Character string specifying which method to use with percentages
for |
A tibble
of class tab
, colored based on differences (from
totals/first cells) and confidence intervals.
# A typical workflow with tabxplor step-by-step functions : data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data %>% tab_plain(sex, hair_color, gender, tot = c("row", "col"), pct = "row", comp = "all") %>% tab_ci("diff", color = "after_ci")
# A typical workflow with tabxplor step-by-step functions : data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data %>% tab_plain(sex, hair_color, gender, tot = c("row", "col"), pct = "row", comp = "all") %>% tab_ci("diff", color = "after_ci")
Bind a list of tabs with the same col_vars (and no tab_vars) into a single tab
tab_compact(tabs)
tab_compact(tabs)
tabs |
A |
A tabxplor_tab
forcats::gss_cat |> tab_many(c(race, rincome), marital, pct = "row", color = "diff") |> tab_compact()
forcats::gss_cat |> tab_many(c(race, rincome), marital, pct = "row", color = "diff") |> tab_compact()
\n
as a linebreak).Get the number of actual rows and the max character length of a table after
being wrapped (count \n
as a linebreak).
tab_get_wrapped_dimensions(tabs, no_tab_vars = FALSE, width_pad = 4L)
tab_get_wrapped_dimensions(tabs, no_tab_vars = FALSE, width_pad = 4L)
tabs |
A data.frame. |
no_tab_vars |
For data.frame of class |
width_pad |
Number of characters lengths between columns. |
Print a tabxplor table in html
tab_kable( tabs, theme = c("light", "dark"), color_type = NULL, html_24_bit = NULL, tooltips = TRUE, popover = NULL, color_legend = TRUE, caption = knitr::opts_current$get("tab.cap"), html_font = NULL, get_data = FALSE, full_width = FALSE, wrap_rows = 35, wrap_cols = 15, whitespace_only = TRUE, ... )
tab_kable( tabs, theme = c("light", "dark"), color_type = NULL, html_24_bit = NULL, tooltips = TRUE, popover = NULL, color_legend = TRUE, caption = knitr::opts_current$get("tab.cap"), html_font = NULL, get_data = FALSE, full_width = FALSE, wrap_rows = 35, wrap_cols = 15, whitespace_only = TRUE, ... )
tabs |
A table made with |
theme |
By default, a white table with black text, Set to |
color_type |
Set to |
html_24_bit |
Use 24bits colors palettes for html tables : set to |
tooltips |
By default, html tooltips are used to display additional informations
at mouse hover. Set to |
popover |
By default, takes |
color_legend |
Print colors legend below the table ?
You can then use a |
caption |
The table caption. For formatting, you need to use a |
html_font |
A string for HTML css font. By default, it uses
|
get_data |
Get the transformed data instead of the html table. |
full_width |
A TRUE or FALSE variable controlling whether the HTML table should have the preferable format for full_width. If not specified, a HTML table will have full width by default but this option will be set to FALSE for a LaTeX table. |
wrap_rows |
By default, rownames are wrapped when larger than 30 characters. |
wrap_cols |
By default, colnames are wrapped when larger than 12 characters. |
whitespace_only |
Set to |
... |
Other arguments to pass to |
A html table (opened in the viewer in RStudio). Differences from totals, confidence intervals, contribution to variance, and unweighted counts, are available in an html tooltip at cells hover.
tabs <- tab(forcats::gss_cat, race, marital, year, pct = "row", color = "diff") tab_kable(tabs, theme = "light", color_type = "text")
tabs <- tab(forcats::gss_cat, race, marital, year, pct = "row", color = "diff") tab_kable(tabs, theme = "light", color_type = "text")
A full-featured function to create, manipulate and format many cross-tables
as one, using colors to make the printed tab more easily readable (in R terminal or
exported to Excel with tab_xl
).
Since objects of class tabxplor_tab
are also of class tibble
, you can then use all
dplyr verbs to modify the result, like select
,
arrange
, filter
or mutate
.
Only breaks for attractions/over-representations (in green) should be given, as a vector of positive doubles, with length between 1 and 5. Breaks for aversions/under-representations (in orange/red) will simply be the opposite.
tab_many( data, row_vars, col_vars, tab_vars, wt, pct = "no", color = "no", OR = "no", chi2 = FALSE, na = "keep", levels = "all", na_drop_all, cleannames = NULL, compact = NULL, other_if_less_than = 0, other_level = "Others", ref = "auto", ref2 = "first", comp = "tab", ci = "no", conf_level = 0.95, method_cell = "wilson", method_diff = "ac", totaltab = "line", totaltab_name = "Ensemble", totrow = TRUE, totcol = "last", total_names = "Total", add_n = TRUE, add_pct = FALSE, digits = 0, subtext = "", filter ) tab_get_vars(tabs, vars = c("row_var", "col_vars", "tab_vars")) is_tab(x) set_color_style( type = c("text", "bg"), theme = NULL, html_24_bit = c("blue_red", "green_red", "no"), custom_palette = NULL ) get_color_style( mode = c("crayon", "color_code"), type = NULL, theme = NULL, html_24_bit = NULL ) set_color_breaks(pct_breaks, mean_breaks, contrib_breaks) get_color_breaks(brk, type = c("positive", "all"))
tab_many( data, row_vars, col_vars, tab_vars, wt, pct = "no", color = "no", OR = "no", chi2 = FALSE, na = "keep", levels = "all", na_drop_all, cleannames = NULL, compact = NULL, other_if_less_than = 0, other_level = "Others", ref = "auto", ref2 = "first", comp = "tab", ci = "no", conf_level = 0.95, method_cell = "wilson", method_diff = "ac", totaltab = "line", totaltab_name = "Ensemble", totrow = TRUE, totcol = "last", total_names = "Total", add_n = TRUE, add_pct = FALSE, digits = 0, subtext = "", filter ) tab_get_vars(tabs, vars = c("row_var", "col_vars", "tab_vars")) is_tab(x) set_color_style( type = c("text", "bg"), theme = NULL, html_24_bit = c("blue_red", "green_red", "no"), custom_palette = NULL ) get_color_style( mode = c("crayon", "color_code"), type = NULL, theme = NULL, html_24_bit = NULL ) set_color_breaks(pct_breaks, mean_breaks, contrib_breaks) get_color_breaks(brk, type = c("positive", "all"))
data |
A data frame. |
row_vars |
The row variable, which will be printed with one level per line. If numeric, it will be converted to factor. If more than one row_var if provided, a different table is made for each of them. |
col_vars |
<tidy-select>
One column is printed for each level of each column variable.
For numeric variables means are calculated, in a single column.
To pass many variables you may use syntax |
tab_vars |
<tidy-select>
One subtable is made for each combination of levels of the tab variables.
To pass many variables you may use syntax |
wt |
A weight variable, of class numeric. Leave empty for unweighted results. |
pct |
The type of percentages to calculate :
The argument is vectorised over both |
color |
The type of colors to print, as a single string. Vectorised over
|
OR |
With
|
chi2 |
Set to |
na |
The policy to adopt with missing values. It must be a single string.
|
levels |
The levels of
|
na_drop_all |
<tidy-select>
Removes all observations with a |
cleannames |
Set to |
compact |
With several |
other_if_less_than |
When set to a positive integer, levels with less count than it will be merged into an "Others" level. |
other_level |
The name of the "Other" level, as a single string. |
ref |
The reference cell to calculate differences and ratios
(used to print
|
ref2 |
A second reference cell is needed to calculate odds ratios
(or relative risks ratios). The first cell of the row or column is used by default.
See |
comp |
The comparison level : by subtables/groups, or for the whole table.
Vectorised over
|
ci |
The type of confidence intervals to calculate, passed to
By default, for percentages, with |
conf_level |
The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%). |
method_cell |
Character string specifying which method to use with percentages
for |
method_diff |
Character string specifying which method to use with percentages
for |
totaltab |
The total table, if there are subtables/groups
(i.e. when
|
totaltab_name |
The name of the total table, as a single string. |
totrow |
By default, total rows are printed.
Set to |
totcol |
The policy with total columns. Vectorised over
|
total_names |
The names of the totals, as a character vector of length one or two.
Use syntax of type |
add_n |
For |
add_pct |
Set to |
digits |
The number of digits to print, as a single integer, or an integer vector
the same length as |
subtext |
A character vector to print rows of legend under the table. |
filter |
A |
tabs |
A |
vars |
In |
x |
A object to test with |
type |
Default to |
theme |
For |
html_24_bit |
Use 24bits colors palettes for html tables : set to |
custom_palette |
Possibility to provide a custom color styles, as a character
vector of 10 html color codes (the five first for over-represented numbers,
the five last for under-represented ones). The result is saved to
|
mode |
By default, |
pct_breaks |
If they are to be changed, the breaks used for percentages.
Default to |
mean_breaks |
If they are to be changed, the breaks used for means.
Default to |
contrib_breaks |
If they are to be changed, the breaks used for contributions to
variance. Default to |
brk |
When missing, return all color breaks. Specify to return a given color
break, among |
A tibble
of class tab
, possibly with colored reading helpers.
When there are two row_vars
or more, a list of tibble
of class tab
.
All non-text columns are of class fmt
, storing all
the data necessary to print formats and colors. Columns with row_var
and
tab_vars
are of class factor
: every added factor
will be
considered as a tab_vars
and used for grouping. To add text columns without
using them in calculations, be sure they are of class character
.
A list with the variables names.
A single logical.
Set global options "tabxplor.color_style_type"
and
"tabxplor.color_style_theme"
, used when printing tab
objects.
A vector of crayon color functions, or a vector of color html codes.
Set the global option "tabxplor.color_breaks" as a list different double vectors, and also returns it invisibly.
The color breaks as a double vector, or list of double vectors.
tab_get_vars()
: Get the variables names of a tabxplor tab
is_tab()
: a test function for class tabxplor_tab
set_color_style()
: define the color style used to print tab
.
get_color_style()
: get color styles as crayon functions or html codes.
set_color_breaks()
: set the breaks used to print colors
get_color_breaks()
: get the breaks currently used to print colors
# Make a summary table with many col_vars, showing only one specific level : library(dplyr) first_lvs <- c("Married", "$25000 or more", "Strong republican", "Protestant") data <- forcats::gss_cat %>% mutate(across( where(is.factor), ~ forcats::fct_relevel(., first_lvs[first_lvs %in% levels(.)]) )) tab_many(data, race, c(marital, rincome, partyid, relig, age, tvhours), levels = "first", pct = "row", chi2 = TRUE, color = "auto") # Can be used with map and tribble to program several tables with different parameters # all at once, in a readable way: library(purrr) library(tibble) pmap( tribble( ~row_var, ~col_vars , ~pct , ~filter , ~subtext , "race" , "marital" , "row", NULL , "Source: GSS 2000-2014", "relig" , c("race", "age"), "row", "year %in% 2000:2010", "Source: GSS 2000-2010", NA_character_, "race" , "no" , NULL , "Source: GSS 2000-2014", ), .f = tab_many, data = forcats::gss_cat, color = "auto", chi2 = TRUE) set_color_style(type = "bg") set_color_breaks( pct_breaks = c(0.05, 0.15, 0.3), mean_breaks = c(1.15, 2, 4), contrib_breaks = c(1, 2, 5) )
# Make a summary table with many col_vars, showing only one specific level : library(dplyr) first_lvs <- c("Married", "$25000 or more", "Strong republican", "Protestant") data <- forcats::gss_cat %>% mutate(across( where(is.factor), ~ forcats::fct_relevel(., first_lvs[first_lvs %in% levels(.)]) )) tab_many(data, race, c(marital, rincome, partyid, relig, age, tvhours), levels = "first", pct = "row", chi2 = TRUE, color = "auto") # Can be used with map and tribble to program several tables with different parameters # all at once, in a readable way: library(purrr) library(tibble) pmap( tribble( ~row_var, ~col_vars , ~pct , ~filter , ~subtext , "race" , "marital" , "row", NULL , "Source: GSS 2000-2014", "relig" , c("race", "age"), "row", "year %in% 2000:2010", "Source: GSS 2000-2010", NA_character_, "race" , "no" , NULL , "Source: GSS 2000-2014", ), .f = tab_many, data = forcats::gss_cat, color = "auto", chi2 = TRUE) set_color_style(type = "bg") set_color_breaks( pct_breaks = c(0.05, 0.15, 0.3), mean_breaks = c(1.15, 2, 4), contrib_breaks = c(1, 2, 5) )
Cross categorical variables with numeric variables, and get a table of means and standard deviations.
tab_num( data, row_var, col_vars, tab_vars, wt, color = c("auto", "diff", "diff_ci", "after_ci"), na = c("keep", "drop", "drop_fct", "drop_num"), ref = "tot", comp = c("tab", "all"), ci = NULL, conf_level = 0.95, totaltab = "line", totaltab_name = "Ensemble", tot = NULL, total_names = "Total", subtext = "", digits = 0, num = FALSE, df = FALSE )
tab_num( data, row_var, col_vars, tab_vars, wt, color = c("auto", "diff", "diff_ci", "after_ci"), na = c("keep", "drop", "drop_fct", "drop_num"), ref = "tot", comp = c("tab", "all"), ci = NULL, conf_level = 0.95, totaltab = "line", totaltab_name = "Ensemble", tot = NULL, total_names = "Total", subtext = "", digits = 0, num = FALSE, df = FALSE )
data |
A data frame. |
row_var |
The row variable, which will be printed with one level per line. If numeric, it will be used as a factor. |
col_vars |
The numeric variables, which will appear in columns :
means and standard deviation are calculated for each levels of |
tab_vars |
<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab variables are converted to factor. |
wt |
A weight variable, of class numeric. Leave empty for unweighted results. |
color |
|
na |
The policy to adopt for missing values in row and tab variables (factors), as a single string.
|
ref |
The reference cell to calculate differences and ratios
(used to print
|
comp |
Comparison level. When |
ci |
The type of confidence intervals to calculate, passed to
|
conf_level |
The confidence level for the confidence intervals, as a single numeric between 0 and 1. Default to 0.95 (95%). |
totaltab |
The total table,
if there are subtables/groups (i.e. when
|
totaltab_name |
The name of the total table, as a single string. |
tot |
The totals :
|
total_names |
The names of the totals, as a character vector of length one or two.
Use syntax of type |
subtext |
A character vector to print rows of legend under the table. |
digits |
The number of digits to print, as a single integer. |
num |
Set to |
df |
Set to |
A tibble
of class tabxplor_tab
. If ...
(tab_vars
)
are provided, a tab
of class tabxplor_grouped_tab
.
All non-text columns are fmt
vectors of class tabxplor_fmt
,
storing all the data necessary to print formats and colors. Columns with row_var
and tab_vars
are of class factor
: every added factor
will be
considered as a tab_vars
and used for grouping. To add text columns without
using them in calculations, be sure they are of class character
.
data <- dplyr::storms %>% tab_prepare(category, wind, na_drop_all = wind) tab_num(data, category, wind, tot = "row", color = "after_ci")
data <- dplyr::storms %>% tab_prepare(category, wind, na_drop_all = wind) tab_num(data, category, wind, tot = "row", color = "after_ci")
tab
Add percentages and diffs to a tab
tab_pct( tabs, pct = "row", digits = NULL, ref = c("tot", "first", "no"), comp = NULL, color = FALSE, just_diff = FALSE )
tab_pct( tabs, pct = "row", digits = NULL, ref = c("tot", "first", "no"), comp = NULL, color = FALSE, just_diff = FALSE )
tabs |
|
pct |
The type of percentages to calculate. |
digits |
The number of digits to print for percentages. As a single integer,
or an integer vector the same length than |
ref |
The reference cell to calculate differences and ratios
(used to print
|
comp |
Comparison level. When |
color |
Set to |
just_diff |
If percentages are already calculated and you just want to recalculate differences. |
A tibble
of class tab
, with percentages displayed, possibly
colored based on differences from totals or first cell.
Plain single cross-table
tab_plain( data, row_var, col_var, tab_vars, wt, pct = "no", color = "no", OR = "no", na = "keep", ref = "auto", ref2 = "first", comp = "tab", totaltab = "line", totaltab_name = "Ensemble", tot = NULL, total_names = "Total", subtext = "", digits = 0, num = FALSE, df = FALSE )
tab_plain( data, row_var, col_var, tab_vars, wt, pct = "no", color = "no", OR = "no", na = "keep", ref = "auto", ref2 = "first", comp = "tab", totaltab = "line", totaltab_name = "Ensemble", tot = NULL, total_names = "Total", subtext = "", digits = 0, num = FALSE, df = FALSE )
data |
A data frame. |
row_var , col_var
|
The row variable, which will be printed with one level per line,
and the column variable, which will be printed with one level per column. Numeric
variables will be used as factors. To calculate means, use |
tab_vars |
<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab variables are converted to factor. |
wt |
A weight variable, of class numeric. Leave empty for unweighted results. |
pct |
The type of percentages to calculate :
|
color |
The type of colors to print, as a single string :
|
OR |
With
|
na |
The policy to adopt with missing values, as a single string.
|
ref |
The reference cell to calculate differences and ratios
(used to print
|
ref2 |
A second reference cell is needed to calculate odds ratios
(or relative risks ratios). The first cell of the row or column is used by default.
See |
comp |
Comparison level. When |
totaltab |
The total table,
if there are subtables/groups (i.e. when
|
totaltab_name |
The name of the total table, as a single string. |
tot |
The totals :
|
total_names |
The names of the totals, as a character vector of length one or two.
Use syntax of type |
subtext |
A character vector to print rows of legend under the table. |
digits |
The number of digits to print, as a single integer. |
num |
Set to |
df |
Set to |
A tibble
of class tabxplor_tab
. If ...
(tab_vars
)
are provided, a tab
of class tabxplor_grouped_tab
.
All non-text columns are fmt
vectors of class tabxplor_fmt
,
storing all the data necessary to print formats and colors. Columns with row_var
and tab_vars
are of class factor
: every added factor
will be
considered as a tab_vars
and used for grouping. To add text columns without
using them in calculations, be sure they are of class character
.
# A typical workflow with tabxplor step-by-step functions : data <- dplyr::starwars %>% tab_prepare(sex, hair_color) data %>% tab_plain(sex, hair_color, tot = c("row", "col"), pct = "row") %>% tab_chi2() %>% tab_ci(color = "after_ci")
# A typical workflow with tabxplor step-by-step functions : data <- dplyr::starwars %>% tab_prepare(sex, hair_color) data %>% tab_plain(sex, hair_color, tot = c("row", "col"), pct = "row") %>% tab_chi2() %>% tab_ci(color = "after_ci")
Print a tabxplor table as plot
tab_plot( tabs, theme = c("light", "dark"), color_type = NULL, html_24_bit = NULL, color_legend = TRUE, caption = NULL, wrap_rows = 35, wrap_cols = 14, whitespace_only = TRUE )
tab_plot( tabs, theme = c("light", "dark"), color_type = NULL, html_24_bit = NULL, color_legend = TRUE, caption = NULL, wrap_rows = 35, wrap_cols = 14, whitespace_only = TRUE )
tabs |
|
theme |
By default, a white table with black text, Set to |
color_type |
Set to |
html_24_bit |
Use 24bits colors palettes for html tables : set to |
color_legend |
Print colors legend below the table ? |
caption |
The table caption. |
wrap_rows |
By default, rownames are wrapped when larger than 30 characters. |
wrap_cols |
By default, colnames are wrapped when larger than 12 characters. |
whitespace_only |
Set to |
A ggplot
object to be printed in the
RStudio
Plots pane or exported as image, using ggtexttable
.
tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |> tab_plot()
tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |> tab_plot()
tab_plain
.Prepare data for tab_plain
.
tab_prepare( data, ..., na_drop_all, cleannames = NULL, other_if_less_than = 0, other_level = "Others" )
tab_prepare( data, ..., na_drop_all, cleannames = NULL, other_if_less_than = 0, other_level = "Others" )
data |
A dataframe. |
... |
Variables then to be passed in |
na_drop_all |
<tidy-select> Removes all
observation with a |
cleannames |
Set to |
other_if_less_than |
When set to a positive integer, levels with less count than it will be merged into an "Others" level. |
other_level |
The name of the "Other" level, as a character vector of length one. |
A modified data.frame.
data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data
data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data
Transform chi2 attribute table of a tabxplor_tab into rows with pvalues.
tab_pvalue_lines(tabs)
tab_pvalue_lines(tabs)
tabs |
A tabxplor_tab (with chi2 table as attribute). |
A tabxplor_tab.
Spread a tab, passing a tab variable to column
tab_spread( tabs, spread_vars, names_prefix, names_sort = FALSE, totname = "Total" )
tab_spread( tabs, spread_vars, names_prefix, names_sort = FALSE, totname = "Total" )
tabs |
A |
spread_vars |
<tidy-select> The tab variables
to pass to column, with a syntax of type |
names_prefix |
String added to the start of every variable name. |
names_sort |
If no |
totname |
The new name of the total rows, as a single string. |
A tibble
of class tab
, with less rows and more columns.
data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2014)) tabs <- tab(data, relig, marital, c(year, race), pct = "row", totaltab = "no", color = "diff", tot = "row", other_if_less_than = 30) tabs %>% dplyr::select(year, race, relig, Married) %>% tab_spread(race)
data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2014)) tabs <- tab(data, relig, marital, c(year, race), pct = "row", totaltab = "no", color = "diff", tot = "row", other_if_less_than = 30) tabs %>% dplyr::select(year, race, relig, Married) %>% tab_spread(race)
tab
Add totals to a tab
tab_tot( tabs, tot = c("row", "col"), name = "Total", totcol = "last", data = NULL )
tab_tot( tabs, tot = c("row", "col"), name = "Total", totcol = "last", data = NULL )
tabs |
|
tot |
|
name |
The names of the totals, as a character vector of length one or two.
Use |
totcol |
|
data |
The original database used to calculate the |
A tibble
of class tab
. Total rows can then be detected using
is_totrow
, and total columns using is_totcol
.
data <- dplyr::starwars %>% tab_prepare(sex, hair_color) data %>% tab_plain(sex, hair_color) %>% tab_tot("col", totcol = "each")
data <- dplyr::starwars %>% tab_prepare(sex, hair_color) data %>% tab_plain(sex, hair_color) %>% tab_tot("col", totcol = "each")
tab
Add total table to a tab
tab_totaltab( tabs, totaltab = c("table", "line", "no"), name = "Ensemble", data = NULL )
tab_totaltab( tabs, totaltab = c("table", "line", "no"), name = "Ensemble", data = NULL )
tabs |
|
totaltab |
If there are subtables, corresponding to the levels of tab_vars,
|
name |
The name of the total table, as a single string. |
data |
The original database used to calculate the |
A tibble
of class tab
. Rows belonging to the total table can then
be detected using is_tottab
.
data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data %>% tab_plain(sex, hair_color, gender) %>% tab_totaltab("line")
data <- dplyr::starwars %>% tab_prepare(sex, hair_color, gender, other_if_less_than = 5, na_drop_all = sex) data %>% tab_plain(sex, hair_color, gender) %>% tab_totaltab("line")
Wrap column names and character/factor variables.
tab_wrap_text( tabs, wrap_rows = 35L, wrap_cols = 15L, exdent = 1, whitespace_only = TRUE, unbreakable_spaces = TRUE, brk = "\n" )
tab_wrap_text( tabs, wrap_rows = 35L, wrap_cols = 15L, exdent = 1, whitespace_only = TRUE, unbreakable_spaces = TRUE, brk = "\n" )
tabs |
A |
wrap_rows |
By default, rownames are wrapped when larger than 30 characters. |
wrap_cols |
By default, colnames are wrapped when larger than 12 characters. |
exdent |
On the second lines or more, the number or characters to use for indentation. |
whitespace_only |
Set to |
unbreakable_spaces |
Set to |
brk |
The string to use for linebreak : |
The same tabxplor_tab
or tibble
.
tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |> tab_wrap_text(wrap_rows = 5L, wrap_cols = 8L)
tab(forcats::gss_cat, race, marital, pct = "row", color = "diff") |> tab_wrap_text(wrap_rows = 5L, wrap_cols = 8L)
To modify the colors used into the Excel table, you can change the
global options with set_color_style
and set_color_breaks
.
tab_xl( tabs, path = NULL, replace = FALSE, open = rlang::is_interactive(), colnames_rotation = 0, remove_tab_vars = TRUE, colwidth = 10, print_color_legend = TRUE, sheets = "auto", n_min = 0, titles, font_text = "DejaVu Sans Condensed", font_num = "DejaVu Sans", text_size = 10, text_size_headers = 9, text_size_subtext = 9, hide_near_zero = Inf, color_type = "text" )
tab_xl( tabs, path = NULL, replace = FALSE, open = rlang::is_interactive(), colnames_rotation = 0, remove_tab_vars = TRUE, colwidth = 10, print_color_legend = TRUE, sheets = "auto", n_min = 0, titles, font_text = "DejaVu Sans Condensed", font_num = "DejaVu Sans", text_size = 10, text_size_headers = 9, text_size_subtext = 9, hide_near_zero = Inf, color_type = "text" )
tabs |
A table made with |
path , replace , open
|
The name, and possibly the path, of the Excel file to
create (possibly without the .xlsx extension). Default path to temporary directory.
Set global option |
colnames_rotation |
Rotate the names of columns to an angle (in degrees). |
remove_tab_vars |
By default, |
colwidth |
The standard width for numeric columns, as a number.
Set to |
print_color_legend |
Should the color legends be printed with the subtexts ? |
sheets |
The Excel sheets options :
|
n_min |
The total count under which a column or row is turned pale grey because there is not enough observation for it to be significant. Default to 0 (not used). |
titles |
The titles of the different tables, as a character vector. When missing titles are given based on the names of the variables. |
font_text , font_num
|
Font for text and for numbers. |
text_size , text_size_headers , text_size_subtext
|
Font sizes of text elements. |
hide_near_zero |
By default all cells displayed as 0 (even rounded)
turn pale grey, to make the distribution of empty cells (and other cells) more visible.
Provide a number to turn grey every cell below it. Set to |
color_type |
By default, the text is colored. Set to |
The table(s) with formatting and colors in an Excel file, as a side effect.
Invisibly returns tabs
.
forcats::gss_cat %>% tab(marital, race, pct = "row", color = "diff") %>% tab_xl()
forcats::gss_cat %>% tab(marital, race, pct = "row", color = "diff") %>% tab_xl()
Table body for class tab
## S3 method for class 'tabxplor_tab' tbl_format_body(x, setup, ...)
## S3 method for class 'tabxplor_tab' tbl_format_body(x, setup, ...)
x |
An object of class tabxplor_tab |
setup |
A setup object from the table |
... |
Other parameters. |
A character vector.
Table headers for class grouped tab
## S3 method for class 'tabxplor_grouped_tab' tbl_sum(x, ...)
## S3 method for class 'tabxplor_grouped_tab' tbl_sum(x, ...)
x |
An object of class tabxplor_tab |
... |
Other parameters. |
A table header
Table headers for class tab
## S3 method for class 'tabxplor_tab' tbl_sum(x, ...)
## S3 method for class 'tabxplor_tab' tbl_sum(x, ...)
x |
An object of class tabxplor_tab |
... |
Other parameters. |
A table header
ungroup method for class tabxplor_grouped_tab
## S3 method for class 'tabxplor_grouped_tab' ungroup(x, ...)
## S3 method for class 'tabxplor_grouped_tab' ungroup(x, ...)
x |
A tibble of class |
... |
Variables to remove from the grouping. |
An object of class tabxplor_tab
or tabxplor_grouped_tab
.
Vec_arith method for fmt
## S3 method for class 'tabxplor_fmt' vec_arith(op, x, y, ...) ## Default S3 method: vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'tabxplor_fmt' vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'numeric' vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'tabxplor_fmt' vec_arith.numeric(op, x, y, ...) ## S3 method for class 'MISSING' vec_arith.tabxplor_fmt(op, x, y, ...)
## S3 method for class 'tabxplor_fmt' vec_arith(op, x, y, ...) ## Default S3 method: vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'tabxplor_fmt' vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'numeric' vec_arith.tabxplor_fmt(op, x, y, ...) ## S3 method for class 'tabxplor_fmt' vec_arith.numeric(op, x, y, ...) ## S3 method for class 'MISSING' vec_arith.tabxplor_fmt(op, x, y, ...)
op |
Operation to do. |
x |
fmt object. |
y |
Second object. |
... |
Other parameter. |
A fmt vector
A fmt vector
A fmt vector
A fmt vector
A fmt vector
A fmt vector
vec_arith.tabxplor_fmt(default)
: default vec_arith method for fmt
vec_arith.tabxplor_fmt(tabxplor_fmt)
: vec_arith method for fmt + fmt
vec_arith.tabxplor_fmt(numeric)
: vec_arith method for fmt + numeric
vec_arith.tabxplor_fmt(MISSING)
: vec_arith method for -fmt
vec_arith.numeric(tabxplor_fmt)
: vec_arith method for numeric + fmt
Convert fmt into character
## S3 method for class 'tabxplor_fmt' vec_cast.character(x, to, ...)
## S3 method for class 'tabxplor_fmt' vec_cast.character(x, to, ...)
x |
A fmt vector |
to |
A character vector |
... |
Other parameter |
A character vector
Convert fmt into double
## S3 method for class 'tabxplor_fmt' vec_cast.double(x, to, ...)
## S3 method for class 'tabxplor_fmt' vec_cast.double(x, to, ...)
x |
A fmt vector |
to |
A double vector |
... |
Other parameter. |
A double vector
Convert fmt into integer
## S3 method for class 'tabxplor_fmt' vec_cast.integer(x, to, ...)
## S3 method for class 'tabxplor_fmt' vec_cast.integer(x, to, ...)
x |
A integer vector |
to |
A fmt vector |
... |
Other parameter. |
An integer vector
Convert double into fmt
## S3 method for class 'tabxplor_fmt.double' vec_cast(x, to, ...)
## S3 method for class 'tabxplor_fmt.double' vec_cast(x, to, ...)
x |
A double vector |
to |
A fmt vector |
... |
Other parameter. |
A fmt vector
Convert integer into fmt
## S3 method for class 'tabxplor_fmt.integer' vec_cast(x, to, ...)
## S3 method for class 'tabxplor_fmt.integer' vec_cast(x, to, ...)
x |
A integer vector |
to |
A fmt vector |
... |
Other parameter. |
A fmt vector
Convert fmt into fmt
## S3 method for class 'tabxplor_fmt.tabxplor_fmt' vec_cast(x, to, ...)
## S3 method for class 'tabxplor_fmt.tabxplor_fmt' vec_cast(x, to, ...)
x |
A fmt vector |
to |
A fmt vector |
... |
Other parameter. |
A fmt vector
Vec_math method for class fmt
## S3 method for class 'tabxplor_fmt' vec_math(.fn, .x, ...)
## S3 method for class 'tabxplor_fmt' vec_math(.fn, .x, ...)
.fn |
A function |
.x |
A fmt object |
... |
Other parameter |
A fmt vector
Compare with fmt vector
## S3 method for class 'tabxplor_fmt' vec_proxy_compare(x, ...)
## S3 method for class 'tabxplor_fmt' vec_proxy_compare(x, ...)
x |
A fmt vector |
... |
Other parameter |
A double vector
Test equality with fmt vector
## S3 method for class 'tabxplor_fmt' vec_proxy_equal(x, ...)
## S3 method for class 'tabxplor_fmt' vec_proxy_equal(x, ...)
x |
A fmt vector |
... |
Other parameter |
A double vector
Abbreviated display name for class fmt in tibbles
## S3 method for class 'tabxplor_fmt' vec_ptype_abbr(x, ...)
## S3 method for class 'tabxplor_fmt' vec_ptype_abbr(x, ...)
x |
A fmt object. |
... |
Other parameter. |
A single string with abbreviated fmt type.
Printed type for class fmt
## S3 method for class 'tabxplor_fmt' vec_ptype_full(x, ...)
## S3 method for class 'tabxplor_fmt' vec_ptype_full(x, ...)
x |
A fmt object. |
... |
Other parameter. |
A single string with full fmt type.
Find common ptype between double and fmt
## S3 method for class 'double.tabxplor_fmt' vec_ptype2(x, y, ...)
## S3 method for class 'double.tabxplor_fmt' vec_ptype2(x, y, ...)
x |
A double vector |
y |
A fmt vector |
... |
Other parameter. |
A fmt vector
Find common ptype between integer and fmt
## S3 method for class 'integer.tabxplor_fmt' vec_ptype2(x, y, ...)
## S3 method for class 'integer.tabxplor_fmt' vec_ptype2(x, y, ...)
x |
An integer vector |
y |
A fmt vector |
... |
Other parameter. |
A fmt vector
Find common ptype between fmt and double
## S3 method for class 'tabxplor_fmt.double' vec_ptype2(x, y, ...)
## S3 method for class 'tabxplor_fmt.double' vec_ptype2(x, y, ...)
x |
A fmt vector |
y |
A double vector |
... |
Other parameter. |
A fmt vector
Find common ptype between fmt and integer
## S3 method for class 'tabxplor_fmt.integer' vec_ptype2(x, y, ...)
## S3 method for class 'tabxplor_fmt.integer' vec_ptype2(x, y, ...)
x |
A fmt vector |
y |
An integer vector |
... |
Other parameter. |
A fmt vector
Find common ptype between fmt and fmt
## S3 method for class 'tabxplor_fmt.tabxplor_fmt' vec_ptype2(x, y, ...)
## S3 method for class 'tabxplor_fmt.tabxplor_fmt' vec_ptype2(x, y, ...)
x |
A fmt object. |
y |
A fmt object. |
... |
Other parameter. |
A fmt vector