| Title: | Audit 'ggplot2' Visualizations for Accessibility and Best Practices |
| Version: | 0.1.0 |
| Description: | Audits 'ggplot2' visualizations for accessibility issues, misleading practices, and readability problems. Checks for color accessibility concerns including colorblind-unfriendly palettes, misleading scale manipulations such as truncated axes and dual y-axes, text readability issues like small fonts and overlapping labels, and general accessibility barriers. Provides comprehensive audit reports with actionable suggestions for improvement. Color vision deficiency simulation uses methods from the 'colorspace' package Zeileis et al. (2020) <doi:10.18637/jss.v096.i01>. Contrast calculations follow WCAG 2.1 guidelines (W3C 2018 https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum). |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | ggplot2, colorspace, grDevices |
| URL: | https://github.com/andytai7/GGenemy |
| BugReports: | https://github.com/andytai7/GGenemy/issues |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2025-10-29 22:38:35 UTC; andytai |
| Author: | Andy Man Yeung Tai [aut, cre] |
| Maintainer: | Andy Man Yeung Tai <[email protected]> |
| Repository: | CRAN |
| Date/Publication: | 2025-11-03 18:50:10 UTC |
Apply automatic fixes to a plot
Description
Apply automatic fixes to a plot
Usage
apply_fixes(plot, audit_report)
Generate fix code based on audit results
Description
Generate fix code based on audit results
Usage
generate_fix_code(audit_report)
Comprehensive Audit of ggplot2 Visualization
Description
Runs all available audit checks on a ggplot2 object and returns a comprehensive report of potential issues and suggestions.
Usage
gg_audit(plot, checks = "all")
Arguments
plot |
A ggplot2 object |
checks |
Character vector of checks to run. Default is "all". Options: "color", "scales", "text", "accessibility", "labels" |
Value
A list with class "gg_audit_report" containing audit results
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point() +
scale_color_manual(values = c("red", "green", "blue"))
report <- gg_audit(p)
print(report)
Comprehensive Accessibility Audit
Description
Checks overall accessibility including color, contrast, and readability.
Usage
gg_audit_accessibility(plot)
Arguments
plot |
A ggplot2 object |
Value
A list of issues, warnings, and suggestions
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point(size = 1)
gg_audit_accessibility(p)
Audit Color Palette for Accessibility Issues
Description
Checks if a ggplot2 object uses colors that may be problematic for colorblind users and provides detailed analysis.
Usage
gg_audit_color(plot)
Arguments
plot |
A ggplot2 object |
Value
A list of issues, warnings, and suggestions
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point() +
scale_color_manual(values = c("red", "green", "blue"))
gg_audit_color(p)
Audit Plot Labels and Annotations
Description
Checks for appropriate titles, labels, and legends.
Usage
gg_audit_labels(plot)
Arguments
plot |
A ggplot2 object |
Value
A list of issues, warnings, and suggestions
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point()
gg_audit_labels(p)
Audit Scales and Axes for Misleading Practices
Description
Checks for truncated axes, inappropriate transformations, and other scale-related issues that can mislead viewers.
Usage
gg_audit_scales(plot)
Arguments
plot |
A ggplot2 object |
Value
A list of issues, warnings, and suggestions
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
ylim(15, 35)
gg_audit_scales(p)
Audit Text Elements for Readability
Description
Checks font sizes, label overlap, and text readability issues.
Usage
gg_audit_text(plot)
Arguments
plot |
A ggplot2 object |
Value
A list of issues, warnings, and suggestions
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(x = rownames(mtcars), y = mpg)) +
geom_col() +
theme(axis.text.x = element_text(size = 6))
gg_audit_text(p)
Simulate Colorblind Vision
Description
Shows how your plot appears to people with different types of color vision deficiency
Usage
gg_simulate_cvd(plot, type = "deutan")
Arguments
plot |
A ggplot2 object |
type |
Type of CVD: "deutan" (green-blind), "protan" (red-blind), or "tritan" (blue-blind) |
Value
A modified ggplot2 object showing the simulated view
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point() +
scale_color_manual(values = c("red", "green", "blue"))
gg_simulate_cvd(p, type = "deutan")
Generate Code Suggestions to Fix Issues
Description
Takes an audit report and generates actionable R code to fix issues. Can also attempt to automatically fix the plot.
Usage
gg_suggest_fixes(audit_report, auto_fix = FALSE, copy_to_clipboard = FALSE)
Arguments
audit_report |
An object returned by gg_audit(), or a ggplot2 object |
auto_fix |
Logical. If TRUE, attempts to automatically apply fixes. Default is FALSE. |
copy_to_clipboard |
Logical. If TRUE, copies suggested code to clipboard. Default is FALSE. |
Value
If auto_fix is TRUE, returns a fixed ggplot2 object. Otherwise returns a list of code suggestions.
Examples
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
geom_point() +
scale_color_manual(values = c("red", "green", "blue"))
# Get suggestions
gg_suggest_fixes(p)
# Auto-fix the plot
p_fixed <- gg_suggest_fixes(p, auto_fix = TRUE)
Print method for audit reports
Description
Print method for audit reports
Usage
## S3 method for class 'gg_audit_report'
print(x, ...)
Arguments
x |
A gg_audit_report object |
... |
Additional arguments (not used) |
Value
Returns the input object invisibly. Called for the side effect of printing a formatted audit report.
Print method for fix suggestions
Description
Print method for fix suggestions
Usage
## S3 method for class 'gg_fix_suggestions'
print(x, ...)
Arguments
x |
A gg_fix_suggestions object |
... |
Additional arguments (not used) |
Value
Returns the input object invisibly. Called for the side effect of printing formatted fix suggestions.