Save a ggplot2 or Base R plot as a standalone HTML file with interactive MAIDR accessibility features.
Arguments
- plot
A ggplot2 object or NULL for Base R auto-detection
- file
File path where to save the HTML file (e.g., "plot.html")
- use_cdn
Logical. Controls where MAIDR.js is loaded from:
TRUE: Use CDN. The file is self-contained but needs internet access when it is viewed.FALSEorNULL(default): Use the bundled files. The MAIDR.js library is written to alib/folder besidefile, which has to travel with it.
- ...
Additional arguments passed to internal functions
Examples
# ggplot2 bar chart
library(ggplot2)
p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
geom_bar(stat = "identity")
# \donttest{
maidr::save_html(p, tempfile(fileext = ".html"))
# }
# ggplot2 violin plot
p_violin <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
geom_violin(fill = "lightblue", alpha = 0.7) +
labs(title = "MPG by Cylinders", x = "Cylinders", y = "MPG")
# \donttest{
maidr::save_html(p_violin, tempfile(fileext = ".html"))
# }
# Base R example (requires interactive session for function patching)
if (interactive()) {
barplot(c(10, 20, 30), names.arg = c("A", "B", "C"))
maidr::save_html(file = tempfile(fileext = ".html"))
}