my.df <-
tibble::tibble(
x = c(1, 2),
y = c(0, 4),
group = c("A", "B"),
tbs = list(a = tibble::tibble(Xa = 1:6, Y = rep(c("x", "y"), 3)),
b = tibble::tibble(Xb = 1:3, Y = "x"))
)
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb() +
expand_limits(x = c(0,3), y = c(-2, 6))
# Hide column names, diplay row names
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(table.colnames = FALSE,
table.rownames = TRUE) +
expand_limits(x = c(0,3), y = c(-2, 6))
# Use a theme for the table
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(table.theme = ttheme_gtlight) +
expand_limits(x = c(0,3), y = c(-2, 6))
# selection and renaming by column position
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(tb.vars = c(value = 1, group = 2),
tb.rows = 1:3) +
expand_limits(x = c(0,3), y = c(-2, 6))
# apply functions to columns
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(tb.vars = c(value = 1, group = 2),
tb.rows = 1:3,
tb.funs = list(group = function(x) {sprintf("italic(%s)", x)},
value = function(x) {ifelse(x > 2, "bold(zz)", x)}),
parse = TRUE) +
expand_limits(x = c(0,3), y = c(-2, 6))
# selection, reordering and renaming by column position
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(tb.vars = c(group = 2, value = 1),
tb.rows = 1:3) +
expand_limits(x = c(0,3), y = c(-2, 6))
# selection and renaming, using partial matching to column name
ggplot(my.df, aes(x, y, label = tbs)) +
stat_fmt_tb(tb.vars = c(value = "X", group = "Y"),
tb.rows = 1:3) +
expand_limits(x = c(0,3), y = c(-2, 6))
Run the code above in your browser using DataLab