if (FALSE) {
# Built-in plot types
plot_data <- list(mtcars$mpg, mtcars$hp, mtcars$qsec)
dat <- data.frame(
Variables = c("mpg", "hp", "qsec"),
Histogram = "",
Density = "",
Bar = "",
BarPct = "",
Line = ""
)
# Random data for sparklines
lines <- lapply(1:3, \(x) data.frame(x = 1:10, y = rnorm(10)))
# Percentage data (values between 0 and 1)
pct_data <- list(0.65, 0.82, 0.41)
tt(dat) |>
plot_tt(j = 2, fun = "histogram", data = plot_data) |>
plot_tt(j = 3, fun = "density", data = plot_data, color = "darkgreen") |>
plot_tt(j = 4, fun = "bar", data = list(2, 3, 6), color = "orange") |>
plot_tt(j = 5, fun = "barpct", data = pct_data, color = "steelblue") |>
plot_tt(j = 6, fun = "line", data = lines, color = "blue") |>
style_tt(j = 2:6, align = "c")
# Custom function example (must have ... argument)
custom_hist <- function(d, ...) {
function() hist(d, axes = FALSE, ann = FALSE, col = "lightblue")
}
tt(data.frame(Variables = "mpg", Histogram = "")) |>
plot_tt(j = 2, fun = custom_hist, data = list(mtcars$mpg))
}
Run the code above in your browser using DataLab