# Generate example data
example_data <- data.frame(
Year = sample(2020:2023, 50, replace = TRUE),
A = sample(c("Type 1", "Type 2"), 50, replace = TRUE),
B = sample(c("Apples", "Oranges", "Bananas"), 50, replace = TRUE),
C = sample(c("Swedish", "Norwegian", "Chilean"), 50, replace = TRUE)
)
### 1 way tables ###
data1 <- example_data |> dplyr::select(Year)
ivo_table_gt(data1)
ivo_table_gt(data1, extra_header = FALSE) # Remove the header
ivo_table_gt(data1, color = "orange") # Change color on table lines
ivo_table_gt(data1, mask = 15) # Counts below <=15 are masked
# With pipes
example_data |>
dplyr::select(Year) |>
ivo_table_gt()
### 2-way tables ###
data2 <- example_data |> dplyr::select(A, B)
data2_swap <- example_data |> dplyr::select(B, A)
# Basic tables:
ivo_table_gt(data2)
ivo_table_gt(data2_swap) # Swap order of the columns
ivo_table_gt(data2, sums = "cols") # Add the sum of each column
ivo_table_gt(data2, sums = "rows") # Add the sum of each row
ivo_table_gt(data2, sums = c("cols", "rows")) # Add the sum of each row and column
ivo_table_gt(data2, caption = "Awesome table") # Add a caption
ivo_table_gt(data2,
caption = "Awesome table",
subtitle = "It's really awesome"
) # Add a subtitle for the title
# Masked tables:
ivo_table_gt(data2, mask = 7) # Counts <= 7 are masked
# Row and column sums are also masked:
ivo_table_gt(
data2,
mask = 3,
sums = c("cols", "rows"),
)
# Add a note at the end of the table:
# (colwidths must be set to the number of columns in the table)
ivo_table_gt(data2, source_note = "This is a footnote.")
### 3-way tables ###
data3 <- example_data |> dplyr::select(C, B, Year)
ivo_table_gt(data3)
ivo_table_gt(data3, sums = c("cols", "rows")) # Add the sum of each column and each row
ivo_table_gt(
data3,
mask = 3,
caption = "Values between 1 and 3 are masked."
)
Run the code above in your browser using DataLab