| Title: | Hand-Drawn Rendering for 'ggplot2' via SVG and 'Rough.js' |
|---|---|
| Description: | Converts 'ggplot2' plots to sketch-style graphics by rendering to SVG with 'svglite' and post-processing the result with 'svg2rough.js'. |
| Authors: | David Schoch [aut, cre] (ORCID: <https://orcid.org/0000-0003-2952-4812>) |
| Maintainer: | David Schoch <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-05-24 06:15:52 UTC |
| Source: | https://github.com/schochastics/ggrough2 |
Downloads a font from Google Fonts and caches it locally so that
rough_plot(p, font = family) can embed it. Requires an internet
connection on first use; subsequent calls for the same family are instant.
add_google_font(name, family = name)add_google_font(name, family = name)
name |
Google Fonts name, e.g. |
family |
Font family name to use later in |
The family name, invisibly.
Constructs a list of optional Rough.js parameters to pass to
rough_plot(). All arguments default to NULL, meaning the Rough.js
library default is used.
rough_options( fill_weight = NULL, hachure_angle = NULL, hachure_gap = NULL, curve_step_count = NULL, curve_fitting = NULL, stroke_line_dash = NULL, stroke_line_dash_offset = NULL, fill_line_dash = NULL, fill_line_dash_offset = NULL, disable_multi_stroke = NULL, disable_multi_stroke_fill = NULL, simplification = NULL, dash_offset = NULL, dash_gap = NULL, zigzag_offset = NULL, preserve_vertices = NULL )rough_options( fill_weight = NULL, hachure_angle = NULL, hachure_gap = NULL, curve_step_count = NULL, curve_fitting = NULL, stroke_line_dash = NULL, stroke_line_dash_offset = NULL, fill_line_dash = NULL, fill_line_dash_offset = NULL, disable_multi_stroke = NULL, disable_multi_stroke_fill = NULL, simplification = NULL, dash_offset = NULL, dash_gap = NULL, zigzag_offset = NULL, preserve_vertices = NULL )
fill_weight |
Width of hachure lines (numeric). For |
hachure_angle |
Angle of hachure lines in degrees (numeric). Default: -41. |
hachure_gap |
Average gap in pixels between hachure lines (numeric). Default: 4× stroke width. |
curve_step_count |
Number of points used to approximate curves (ellipses, arcs). Default: 9. |
curve_fitting |
How closely rendered dimensions match specified dimensions for curves (0–1). Default: 0.95. |
stroke_line_dash |
Dashed stroke pattern — a numeric vector of
dash/gap lengths (e.g. |
stroke_line_dash_offset |
Phase offset for dashed strokes (numeric). |
fill_line_dash |
Like |
fill_line_dash_offset |
Like |
disable_multi_stroke |
Logical. If |
disable_multi_stroke_fill |
Logical. If |
simplification |
Simplify SVG paths by this factor (0–1). 0 = no simplification. Useful for giving complex paths a sketchy feel. |
dash_offset |
Nominal dash length (px) for |
dash_gap |
Nominal gap between dashes (px) for |
zigzag_offset |
Nominal width of zigzag triangles (px) for
|
preserve_vertices |
Logical. If |
A named list suitable for the options argument of rough_plot().
Render a ggplot as a hand-drawn sketch
rough_plot( plot, width = 7, height = 5, roughness = 1.5, bowing = 1, fill_style = "hachure", bg_fill_style = "solid", seed = NULL, preserve_text = TRUE, font = "IndieFlower", options = rough_options() )rough_plot( plot, width = 7, height = 5, roughness = 1.5, bowing = 1, fill_style = "hachure", bg_fill_style = "solid", seed = NULL, preserve_text = TRUE, font = "IndieFlower", options = rough_options() )
plot |
A ggplot object. |
width, height
|
Plot size in inches. |
roughness |
Rough.js roughness parameter. |
bowing |
Rough.js bowing parameter. |
fill_style |
Rough.js fill style for data elements (geoms). |
bg_fill_style |
Rough.js fill style for background elements (panel/plot
backgrounds). Defaults to |
seed |
Optional seed for deterministic randomness. |
preserve_text |
Keep text unchanged. |
font |
Font family name to use for text labels, or |
options |
A list of additional Rough.js drawing options, typically
created with |
An htmlwidget.
Save a roughened plot as HTML
save_rough_html(plot, file, ...)save_rough_html(plot, file, ...)
plot |
A ggplot object. |
file |
Output HTML file. |
... |
Passed to rough_plot(). |
Renders the plot in a headless browser so the Rough.js sketch is fully drawn before the image is captured. Requires the webshot2 package and a local Chrome/Chromium installation.
save_rough_image(plot, file, ..., delay = 2, vwidth = 992, vheight = 744)save_rough_image(plot, file, ..., delay = 2, vwidth = 992, vheight = 744)
plot |
A ggplot object. |
file |
Output file path. Extension must be |
... |
Additional arguments passed to |
delay |
Seconds to wait after page load before capturing. Increase if the output is blank or partially rendered. |
vwidth, vheight
|
Browser viewport dimensions in pixels. |
file, invisibly.