R has some great packages for creating nice-looking tables. Packages like gt and flextable allow the user to create a wide range of tables, with lots of flexibility in how these are presented and formatted. The downside to these Swiss army knife-style packages is that simple tasks, like creating a frequency table, require a lot of typing. Enter ivo.table, a package for creating great-looking frequency tables and contingency tables without any hassle.
News in version 0.6
A new version of the ivo.table package is now available on CRAN. Updates include:
Let’s look at some examples using the penguins data from the palmerpenguins package. Say that we want to create a contingency table showing the counts of the categorical variables species, sex, and island. We can use ftable along with dplyr’s select:
ivo_table has lots of options for customising the look of your table. You can change the colours and fonts used, highlight columns, rows or cells, make columns bold, and more. Let’s look at some examples.
Change the font to Courier, use red instead of green, and make the names in the sex column bold:
Add a caption and highlight the cell on the fourth row of the third column:
penguins |>select(species, sex, island) |>ivo_table(caption ="A table with penguins in it",highlight_cols =3,highlight_rows =4)
species
sex
island
Adelie
Chinstrap
Gentoo
female
Biscoe
22
0
58
Dream
27
34
0
Torgersen
24
0
0
male
Biscoe
22
0
61
Dream
28
34
0
Torgersen
23
0
0
(Missing)
Biscoe
0
0
5
Dream
1
0
0
Torgersen
5
0
0
ivo_table returns a flextable object, meaning that all functions used to style flextables can be used. For instance, you can change the font size used in different parts of the table using flextable::fontsize and change the background colour using flextable::bg:
penguins |>select(species, sex, island) |>ivo_table(color ="darkblue") |> flextable::fontsize(size =8, part ="body") |> flextable::fontsize(size =12, part ="header") |> flextable::bg(bg ="pink", part ="all")