# Small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive
data(tips)
p_(ggally_table(tips, mapping = aes(x = smoker, y = sex)))
p_(ggally_table(tips, mapping = aes(x = day, y = time)))
p_(ggally_table(tips, mapping = aes(x = smoker, y = sex, colour = smoker)))
# colour is kept only if equal to x or y
p_(ggally_table(tips, mapping = aes(x = smoker, y = sex, colour = day)))
# diagonal version
p_(ggally_tableDiag(tips, mapping = aes(x = smoker)))
# custom label size and color
p_(ggally_table(tips, mapping = aes(x = smoker, y = sex), size = 16, color = "red"))
# display column proportions
p_(ggally_table(
tips,
mapping = aes(x = day, y = sex, label = scales::percent(after_stat(col.prop)))
))
# draw table cells
p_(ggally_table(
tips,
mapping = aes(x = smoker, y = sex),
geom_tile_args = list(colour = "black", fill = "white")
))
# Use standardized residuals to fill table cells
p_(ggally_table(
as.data.frame(Titanic),
mapping = aes(
x = Class, y = Survived, weight = Freq,
fill = after_stat(std.resid),
label = scales::percent(after_stat(col.prop), accuracy = .1)
),
geom_tile_args = list(colour = "black")
) +
scale_fill_steps2(breaks = c(-3, -2, 2, 3), show.limits = TRUE))
Run the code above in your browser using DataLab