| Title: | Hand-Drawn Charts, Drawings and Slides in the 'Excalidraw' Style |
|---|---|
| Description: | Build, read and write 'Excalidraw' scenes from R, turn 'ggplot2' and base graphics into editable hand-drawn drawings, and render them offline with the same 'rough.js' engine and handwriting fonts that 'Excalidraw' uses. Includes the 'Excalidraw' editor as an 'htmlwidget'. Not affiliated with or endorsed by Excalidraw. |
| Authors: | Joseph S. Miller [aut, cre], Excalidraw [ctb, cph] (Excalidraw editor, shape logic ported in inst/js/exc-shapes.js, Excalifont, sticker libraries), Preet Shihn [ctb, cph] (rough.js), Stephen Ruiz [ctb, cph] (perfect-freehand), pieroxy [ctb, cph] (lz-string), Florian Koerner [ctb, cph] (DiceBear), Pablo Stanley [ctb] (Open Peeps artwork (CC0)), Ellinor Rapp [cph] (Virgil font), Shannon Miwa [cph] (Comic Shanns font) |
| Maintainer: | Joseph S. Miller <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-27 11:07:39 UTC |
| Source: | https://github.com/jossammil/scratchy |
Add sticky notes, callouts, marks and titles to a scene. Positions use the
plot's data values for scenes made from a ggplot (see exc_data_to_px()),
or px when wrapped in I().
exc_note( scene, text, x, y, to = NULL, width = 200, fill = "yellow", angle = -2, panel = 1, ... ) exc_callout(scene, text, x, y, dx = 60, dy = -60, panel = 1, ...) exc_mark( scene, x, y, type = c("circle", "box", "underline", "highlight", "strike", "bracket", "cross"), color = NULL, padding = 6, panel = 1, ... ) exc_title(scene, title, subtitle = NULL, size = 36, underline = TRUE, ...)exc_note( scene, text, x, y, to = NULL, width = 200, fill = "yellow", angle = -2, panel = 1, ... ) exc_callout(scene, text, x, y, dx = 60, dy = -60, panel = 1, ...) exc_mark( scene, x, y, type = c("circle", "box", "underline", "highlight", "strike", "bracket", "cross"), color = NULL, padding = 6, panel = 1, ... ) exc_title(scene, title, subtitle = NULL, size = 36, underline = TRUE, ...)
scene |
An |
text |
The text. |
x, y
|
Where to put it: data values, or px in |
to |
Optional |
width |
Maximum width of the note in px before the text wraps. |
fill |
Note colour (an Excalidraw hue name or a colour). |
angle |
Tilt in degrees, for a casually stuck-on look. |
panel |
Panel number in faceted plots. |
... |
Style properties passed to the elements, such as |
dx, dy
|
Offset in px from the spot to the text. |
type |
|
color |
Mark colour. Highlights default to a translucent yellow. |
padding |
Space in px between the marked area and the mark. |
title, subtitle
|
Title and optional subtitle text. |
size |
Title font size in px (Excalidraw's XL is 36). |
underline |
Draw a hand-drawn underline under the title. |
exc_note(): a sticky note, optionally with an arrow pointing to a spot.
exc_callout(): a handwritten remark with a curved arrow to a spot.
exc_mark(): circle, box, underline, highlight, strike through,
bracket or cross out a value or a range, like rough-notation.
exc_title(): a big title with a hand-drawn underline, above the drawing.
The scene with the annotation added.
library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") as_excalidraw(p) |> exc_title("What do people drive?") |> exc_mark(x = "suv", y = c(0, 62), type = "box") |> exc_note("SUVs win!", x = "midsize", y = 55, to = c("suv", 50)) |> exc_callout("so few", x = "2seater", y = 5)library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") as_excalidraw(p) |> exc_title("What do people drive?") |> exc_mark(x = "suv", y = c(0, 62), type = "box") |> exc_note("SUVs win!", x = "midsize", y = 55, to = c("suv", 50)) |> exc_callout("so few", x = "2seater", y = 5)
Draws the plot with svglite::svglite(), reads back every line, box,
point, polygon and piece of text, and rebuilds them as Excalidraw
elements: bars become hachure-filled rectangles, lines become sketchy
lines, text uses a handwriting font. The result can be saved with
write_excalidraw() and edited by hand in Excalidraw, or drawn in R with
exc_save() / plot().
as_excalidraw(x, ...) ## S3 method for class 'ggplot' as_excalidraw( x, width = 800, height = 500, theme = theme_excalidraw(), fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class 'formula' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class ''function'' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class 'grob' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... )as_excalidraw(x, ...) ## S3 method for class 'ggplot' as_excalidraw( x, width = 800, height = 500, theme = theme_excalidraw(), fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class 'formula' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class ''function'' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... ) ## S3 method for class 'grob' as_excalidraw( x, width = 800, height = 500, fill_style = "hachure", roughness = "artist", outline = TRUE, font = "Excalifont", snap = TRUE, preset = NULL, seed = 1, max_elements = 5000, id = NULL, ... )
x |
A ggplot, a formula such as |
... |
Unused. |
width, height
|
Size of the drawing in px (Excalidraw units, 96 per inch). |
theme |
For ggplots, a theme added before drawing. Defaults to
|
fill_style |
Fill style for filled shapes: |
roughness |
Sloppiness: |
outline |
Give filled shapes without a border a darker outline in the same hue, like Excalidraw shapes. |
font |
Font for all text (see |
snap |
Round stroke widths to Excalidraw's thin / bold / extra bold. |
preset |
Optional |
seed |
Seed for the hand-drawn wobble, so the same plot always looks the same. |
max_elements |
Warn when the scene has more elements than this; Excalidraw slows down with very many. |
id |
A name for the chart. All its elements are grouped and tagged
with it, so the chart can be found later, for example to swap it for a
new version with |
For ggplot2 plots the scene also remembers how data values map to
positions, so annotations such as exc_note() and exc_mark() can be
placed with data coordinates.
An exc_scene.
library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() + scale_fill_excalidraw() s <- as_excalidraw(p) s write_excalidraw(s, tempfile(fileext = ".excalidraw")) as_excalidraw(~ hist(faithful$eruptions, col = "#ffec99", main = "Old Faithful"))library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() + scale_fill_excalidraw() s <- as_excalidraw(p) s write_excalidraw(s, tempfile(fileext = ".excalidraw")) as_excalidraw(~ hist(faithful$eruptions, col = "#ffec99", main = "Old Faithful"))
One row per element with its main properties. Useful for finding
elements to change with exc_modify().
## S3 method for class 'exc_scene' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'exc_scene' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
An |
row.names, optional
|
Ignored. |
... |
Ignored. |
A data frame.
Add elements to a scene
exc_add(scene, ...)exc_add(scene, ...)
scene |
An |
... |
Elements to add on top of the existing ones. |
The updated scene.
exc_scene() |> exc_add(exc_text("Hello", 0, 0))exc_scene() |> exc_add(exc_text("Hello", 0, 0))
Saves a scene as an animated SVG in which the drawing sketches itself:
elements appear one after another in z-order, each stroke traced from start
to end (CSS stroke-dasharray animations), fills fade in once their
outline is done, and text is written in letter by letter. The strokes are
the native renderer's, so the finished drawing matches exc_save(). Save
to a .gif file to record the animation in headless Chrome instead.
exc_animate( scene, file, duration = 5, loop = FALSE, hold = 2, text = c("write", "fade"), padding = 10, background = TRUE, paper = NULL, frames = TRUE, scale = 1, fps = 20 )exc_animate( scene, file, duration = 5, loop = FALSE, hold = 2, text = c("write", "fade"), padding = 10, background = TRUE, paper = NULL, frames = TRUE, scale = 1, fps = 20 )
scene |
An |
file |
Output path ending in |
duration |
Seconds from blank canvas to finished drawing. Each element gets time in proportion to how much it has to draw. |
loop |
Replay forever, showing the finished drawing for |
hold |
Seconds the finished drawing stays up before a loop starts again. |
text |
How text appears: |
padding |
Space around the drawing, in px. |
background |
Draw the background colour ( |
paper |
Optional paper background; see |
frames |
Draw frame outlines and names. |
scale |
Size: 1 = one pixel per scene px. For GIFs this is the pixel
density, as in |
fps |
Frames per second for GIFs (at most 50). |
The SVG plays in web browsers, also inside <img> tags, slides and README
files. Viewers who ask their system for reduced motion, and programs that
don't run CSS animations, see the finished drawing.
file, invisibly.
s <- exc_scene( exc_rect(0, 0, 160, 80, label = "Idea", fill = "yellow"), exc_arrow(c(170, 270), c(40, 40)), exc_ellipse(280, 0, 150, 80, label = "Chart", fill = "blue", fill_style = "hachure") ) f <- tempfile(fileext = ".svg") exc_animate(s, f, duration = 3) ## Not run: browseURL(f) # A looping GIF (needs Chrome and the gifski or magick package) exc_animate(s, "idea.gif", loop = TRUE) ## End(Not run)s <- exc_scene( exc_rect(0, 0, 160, 80, label = "Idea", fill = "yellow"), exc_arrow(c(170, 270), c(40, 40)), exc_ellipse(280, 0, 150, 80, label = "Chart", fill = "blue", fill_style = "hachure") ) f <- tempfile(fileext = ".svg") exc_animate(s, f, duration = 3) ## Not run: browseURL(f) # A looping GIF (needs Chrome and the gifski or magick package) exc_animate(s, "idea.gif", loop = TRUE) ## End(Not run)
Bounding box of a scene
exc_bbox(scene, stroke = TRUE)exc_bbox(scene, stroke = TRUE)
scene |
An |
stroke |
Include half the stroke width around each element. |
A named numeric vector: xmin, ymin, xmax, ymax, width,
height, in px.
Look up a colour by Excalidraw hue name
exc_color(hue, shade = 5)exc_color(hue, shade = 5)
hue |
One of |
shade |
Shade from 1 (lightest) to 5 (strongest). |
A hex colour string.
exc_color("blue") exc_color("yellow", 2)exc_color("blue") exc_color("yellow", 2)
Renders D2 diagram text with D2's hand-drawn
--sketch mode and returns it as a scene holding the SVG as an image
(so you can annotate it, place it next to charts or save it). Needs the
d2 command-line tool (on macOS: brew install d2). For diagrams made of
editable Excalidraw shapes, use exc_mermaid() instead.
exc_d2( code, sketch = TRUE, font = "Excalifont", theme = NULL, layout = NULL, pad = 20, scale = 1 )exc_d2( code, sketch = TRUE, font = "Excalifont", theme = NULL, layout = NULL, pad = 20, scale = 1 )
code |
D2 diagram text, such as |
sketch |
Use D2's hand-drawn style. |
font |
Font for the labels (see |
theme |
D2 theme id (see |
layout |
Layout engine, such as |
pad |
Padding around the diagram, in px. |
scale |
Size multiplier for the image. |
The labels use a handwriting font (Excalifont by default), embedded in the
SVG so the diagram looks the same in the Excalidraw editor, in browsers
and in SVG exports. R's own PNG and PDF output draws SVG images with rsvg,
which ignores embedded fonts: there the labels use the font only if it is
installed on the computer (see exc_install_fonts()).
An exc_scene.
## Not run: exc_d2("data -> sketch: ggplot2\nsketch -> share: excalidraw") |> plot() ## End(Not run)## Not run: exc_d2("data -> sketch: ggplot2\nsketch -> share: excalidraw") |> plot() ## End(Not run)
Scenes made by as_excalidraw() from a ggplot remember how data values
map to px. Discrete values such as "suv" map to the centre of their
category. Wrap values in I() to give px directly.
exc_data_to_px(scene, x, y, panel = 1)exc_data_to_px(scene, x, y, panel = 1)
scene |
An |
x, y
|
Data values (or px wrapped in |
panel |
Panel number for faceted plots, in layout order. |
A list with x and y in px.
Opens the scene in the real Excalidraw editor (in the RStudio viewer or a browser). Draw, move things around, add notes, then click Done to get the edited scene back in R.
exc_edit( scene = exc_scene(), viewer = shiny::paneViewer(minHeight = 650), title = "Edit drawing" )exc_edit( scene = exc_scene(), viewer = shiny::paneViewer(minHeight = 650), title = "Edit drawing" )
scene |
An |
viewer |
Where to open the editor; see |
title |
Title shown above the editor. |
The edited exc_scene, or the original if nothing was changed.
NULL (invisibly) if you click Cancel.
if (interactive()) { s <- exc_edit(exc_scene(exc_text("Draw something!", 0, 0, font_size = 28))) write_excalidraw(s, "drawing.excalidraw") }if (interactive()) { s <- exc_edit(exc_scene(exc_text("Draw something!", 0, 0, font_size = 28))) write_excalidraw(s, "drawing.excalidraw") }
Some fun fonts can't be bundled because of their licence, so they are downloaded on request, stored in your user data folder and registered for this and future sessions.
exc_font_fetch(name = c("xkcd"))exc_font_fetch(name = c("xkcd"))
name |
Which font to download. |
"xkcd": the xkcd Script handwriting font by the iPython team, made
from Randall Munroe's handwriting (CC BY-NC 3.0: non-commercial use).
The font's family name, invisibly. Use it as font =.
## Not run: exc_font_fetch("xkcd") sketch(p, preset = "xkcd", font = "xkcd Script") ## End(Not run)## Not run: exc_font_fetch("xkcd") sketch(p, preset = "xkcd", font = "xkcd Script") ## End(Not run)
Lists Excalidraw's own fonts and the extra handwriting fonts bundled with the package. Fonts without an Excalidraw id still work in R; when the file is opened in Excalidraw they display as Excalifont.
exc_fonts()exc_fonts()
A data frame with the font name, its Excalidraw id, whether a
font file is bundled, and the licence.
exc_fonts()exc_fonts()
A frame is a named box that holds other elements. Excalidraw uses frames for slides and for exporting part of a drawing.
exc_frame( x, y, width, height, name = NULL, contents = NULL, id = NULL, custom = NULL )exc_frame( x, y, width, height, name = NULL, contents = NULL, id = NULL, custom = NULL )
x, y, width, height
|
Position and size in px. |
name |
Frame title shown above it. |
contents |
Elements to place inside the frame. |
id |
Element id. Generated if |
custom |
A list stored in the element's |
An exc_elements object: the contents followed by the frame.
exc_frame(0, 0, 400, 300, "Slide 1", contents = exc_text("Hi", 20, 20))exc_frame(0, 0, 400, 300, "Slide 1", contents = exc_text("Hi", 20, 20))
Builds a grid grob that draws the scene the way Excalidraw does: rough.js strokes and fills from each element's seed, Excalidraw's arrowheads, and text in the bundled handwriting fonts. The sketchy geometry is computed once; the grob rescales to whatever space it is drawn in, keeping the aspect ratio.
exc_grob( scene, padding = 10, background = TRUE, text = c("auto", "outline", "font"), scale = NULL, frames = TRUE, paper = NULL, name = NULL )exc_grob( scene, padding = 10, background = TRUE, text = c("auto", "outline", "font"), scale = NULL, frames = TRUE, paper = NULL, name = NULL )
scene |
An |
padding |
Space around the drawing, in px (Excalidraw uses 10). |
background |
Draw the scene's background colour. |
text |
How to draw text: |
scale |
|
frames |
Draw frame outlines and names. |
paper |
Optional paper background: |
name |
Grob name. |
A grob of class exc_grob.
s <- exc_scene(exc_rect(0, 0, 120, 60, label = "hi", fill = "yellow", fill_style = "hachure")) grid::grid.newpage() grid::grid.draw(exc_grob(s))s <- exc_scene(exc_rect(0, 0, 120, 60, label = "hi", fill = "yellow", fill_style = "hachure")) grid::grid.newpage() grid::grid.draw(exc_grob(s))
Grouped elements select and move together in Excalidraw.
exc_group(..., id = NULL)exc_group(..., id = NULL)
... |
|
id |
Group id. Generated if |
An exc_elements object.
exc_group(exc_rect(0, 0, 50, 50), exc_text("box", 0, 60))exc_group(exc_rect(0, 0, 50, 50), exc_text("box", 0, 60))
Embeds an image file (PNG, JPEG, GIF, SVG or WebP) in the scene.
exc_image( file, x, y, width = NULL, height = NULL, ..., angle = 0, group = NULL, id = NULL, custom = NULL )exc_image( file, x, y, width = NULL, height = NULL, ..., angle = 0, group = NULL, id = NULL, custom = NULL )
file |
Path to the image file. |
x, y
|
Top-left corner in px. |
width, height
|
Size in px. If only one is given the other keeps the image's aspect ratio; if neither, the image's own size is used (PNG, GIF and SVG only). |
... |
Style properties such as |
angle |
Rotation in degrees, clockwise, around the shape's centre. |
group |
Group id(s) to put the element in. See |
id |
Element id. Generated if |
custom |
A list stored in the element's |
An exc_elements object carrying the image data.
Copies the bundled fonts (Excalifont, Virgil, Comic Shanns, Caveat and
the others in exc_fonts()) into your user font folder, so other
programs such as PowerPoint, Keynote or Word can show them. Nothing is
installed unless you call this.
exc_install_fonts(dir = NULL, overwrite = FALSE)exc_install_fonts(dir = NULL, overwrite = FALSE)
dir |
Font folder. Defaults to |
overwrite |
Replace fonts that are already there. |
The installed file paths, invisibly.
Load an Excalidraw library from a file or the web
exc_library(path)exc_library(path)
path |
A |
An exc_library; place items with exc_library_item().
Points are absolute positions in px. Give x and y vectors, or a
two-column matrix or data frame as x.
exc_line( x, y = NULL, ..., style = NULL, closed = FALSE, curved = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_arrow( x, y = NULL, ..., start = NULL, end = "arrow", curved = FALSE, elbowed = FALSE, label = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_freedraw( x, y = NULL, ..., pressures = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL )exc_line( x, y = NULL, ..., style = NULL, closed = FALSE, curved = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_arrow( x, y = NULL, ..., start = NULL, end = "arrow", curved = FALSE, elbowed = FALSE, label = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_freedraw( x, y = NULL, ..., pressures = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL )
x, y
|
Point coordinates. |
... |
Style properties such as |
style |
An |
closed |
Join the last point back to the first. Closed lines can be
filled with |
curved |
Draw a smooth curve through the points instead of straight segments. |
angle |
Rotation in degrees, clockwise, around the shape's centre. |
group |
Group id(s) to put the element in. See |
id |
Element id. Generated if |
custom |
A list stored in the element's |
seed |
The rough.js seed that decides the element's wobble. Random
(from R's RNG) if |
start, end
|
Arrowheads: |
elbowed |
Draw the arrow with right-angle elbows. |
label |
Optional text placed at the middle of the arrow. |
pressures |
Optional pen pressures (0-1), one per point. If |
An exc_elements object.
exc_line(c(0, 50, 100), c(0, 40, 0)) exc_line(c(0, 80, 40), c(0, 0, 60), closed = TRUE, fill = "green") exc_arrow(c(0, 150), c(0, 0), label = "next") exc_freedraw(cos(seq(0, 6, 0.2)) * 30, sin(seq(0, 6, 0.2)) * 30)exc_line(c(0, 50, 100), c(0, 40, 0)) exc_line(c(0, 80, 40), c(0, 0, 60), closed = TRUE, fill = "green") exc_arrow(c(0, 150), c(0, 0), label = "next") exc_freedraw(cos(seq(0, 6, 0.2)) * 30, sin(seq(0, 6, 0.2)) * 30)
Converts Mermaid text (flowcharts, sequence and class diagrams) to Excalidraw elements with Excalidraw's own converter, run in headless Chrome (needs the chromote package and Chrome or Chromium). Other diagram types come back as an embedded image.
exc_mermaid(code, font_size = 20)exc_mermaid(code, font_size = 20)
code |
Mermaid diagram text. |
font_size |
Font size for the diagram text. |
An exc_scene.
## Not run: exc_mermaid("flowchart LR\n idea[Idea] --> sketch[Sketch] --> chart{{Chart!}}") |> exc_save("flow.png") ## End(Not run)## Not run: exc_mermaid("flowchart LR\n idea[Idea] --> sketch[Sketch] --> chart{{Chart!}}") |> exc_save("flow.png") ## End(Not run)
Select elements with a condition on the columns of
as.data.frame(scene) and set new property values.
exc_modify(scene, where = TRUE, ...)exc_modify(scene, where = TRUE, ...)
scene |
An |
where |
A condition using columns such as |
... |
Properties to set: style names as in |
The updated scene.
s <- exc_scene(exc_text("a", 0, 0), exc_rect(0, 30, 50, 50)) exc_modify(s, type == "rectangle", fill = "red", fill_style = "solid")s <- exc_scene(exc_text("a", 0, 0), exc_rect(0, 30, 50, 50)) exc_modify(s, type == "rectangle", fill = "red", fill_style = "solid")
Names of the paper backgrounds the native renderer can draw behind a
scene. Pass one as paper = to exc_save(), exc_grob() or plot().
exc_papers()exc_papers()
A character vector.
exc_papers()exc_papers()
Draws a person in Pablo Stanley's Open Peeps style (CC0), generated
offline with the DiceBear Open Peeps generator (MIT). The same seed
always gives the same person. Peeps are SVG images: crisp in Excalidraw
and in SVG/PDF output (the native renderer needs the rsvg package).
exc_peep( scene = NULL, x = 0, y = 0, size = 160, seed = NULL, face = NULL, head = NULL, accessories = NULL, facial_hair = NULL, skin = NULL, clothing = NULL, ..., panel = 1 ) exc_peep_options()exc_peep( scene = NULL, x = 0, y = 0, size = 160, seed = NULL, face = NULL, head = NULL, accessories = NULL, facial_hair = NULL, skin = NULL, clothing = NULL, ..., panel = 1 ) exc_peep_options()
scene |
An |
x, y
|
Top-left corner, in px (or data values for converted ggplots). |
size |
Width and height in px. |
seed |
Any string or number; each gives a different person. |
face, head, accessories, facial_hair
|
Optional choices, such as
|
skin, clothing
|
Colours (hex, without or with |
... |
Other DiceBear Open Peeps options. |
panel |
Panel number for faceted plots. |
The scene with the person added, or an exc_elements object if
scene is NULL.
exc_peep_options(): a named list of the allowed values for each
option.
exc_scene() |> exc_peep(0, 0, seed = "Ada", face = "smile") |> exc_peep(170, 0, seed = "Grace", clothing = "#a5d8ff")exc_scene() |> exc_peep(0, 0, seed = "Ada", face = "smile") |> exc_peep(170, 0, seed = "Grace", clothing = "#a5d8ff")
Writes one slide per scene (or per chart, or per Excalidraw frame) to a
PowerPoint file. By default each drawing is placed as editable vector
shapes (with the rvg package), so strokes can be recoloured or moved in
PowerPoint; use vector = FALSE for a picture instead.
exc_pptx( x, path, titles = NULL, vector = TRUE, text = c("outline", "font"), template = NULL, scale = 2 )exc_pptx( x, path, titles = NULL, vector = TRUE, text = c("outline", "font"), template = NULL, scale = 2 )
x |
An |
path |
Output |
titles |
Slide titles (recycled). |
vector |
Place drawings as editable vector shapes ( |
text |
|
template |
Optional |
scale |
Pixel density for pictures when |
Text is drawn as shapes by default so it keeps the handwriting font on any
computer. With text = "font" it stays editable text, which shows in the
handwriting font only where the fonts are installed (see
exc_install_fonts()).
path, invisibly.
## Not run: library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") exc_pptx(list(p, exc_mermaid("flowchart LR\n A --> B")), "talk.pptx", titles = c("What people drive", "How it works")) ## End(Not run)## Not run: library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") exc_pptx(list(p, exc_mermaid("flowchart LR\n A --> B")), "talk.pptx", titles = c("What people drive", "How it works")) ## End(Not run)
A preset bundles sloppiness, font, ink colour, fill style and paper into a named look:
"whiteboard": Excalidraw's own look.
"xkcd": wobblier, bowed lines and a comic font.
"blueprint": white ink on blueprint paper.
"chalkboard": chalky lines on a dark board.
"pencil": thin grey lines on lined notebook paper.
"marker": thick marker strokes and a bold font.
exc_preset( name = c("whiteboard", "xkcd", "blueprint", "chalkboard", "pencil", "marker") )exc_preset( name = c("whiteboard", "xkcd", "blueprint", "chalkboard", "pencil", "marker") )
name |
Preset name. |
An exc_preset object (a list).
exc_preset("blueprint")exc_preset("blueprint")
Excalidraw shapes: rectangles, ellipses and diamonds
exc_rect( x, y, width, height, label = NULL, ..., style = NULL, rounded = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_ellipse( x, y, width, height, label = NULL, ..., style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_diamond( x, y, width, height, label = NULL, ..., style = NULL, rounded = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL )exc_rect( x, y, width, height, label = NULL, ..., style = NULL, rounded = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_ellipse( x, y, width, height, label = NULL, ..., style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL ) exc_diamond( x, y, width, height, label = NULL, ..., style = NULL, rounded = FALSE, angle = 0, group = NULL, id = NULL, custom = NULL, seed = NULL )
x, y
|
Top-left corner of the shape's bounding box, in px. |
width, height
|
Size in px. |
label |
Optional text drawn centred inside the shape. It stays attached to the shape when you edit it in Excalidraw. |
... |
Style properties such as |
style |
An |
rounded |
Round the corners (rectangles and diamonds). |
angle |
Rotation in degrees, clockwise, around the shape's centre. |
group |
Group id(s) to put the element in. See |
id |
Element id. Generated if |
custom |
A list stored in the element's |
seed |
The rough.js seed that decides the element's wobble. Random
(from R's RNG) if |
An exc_elements object.
exc_rect(0, 0, 160, 80, label = "Hello", fill = "yellow", fill_style = "solid") exc_ellipse(200, 0, 120, 80, fill = "#a5d8ff", fill_style = "hachure") exc_diamond(360, 0, 120, 100, rounded = TRUE)exc_rect(0, 0, 160, 80, label = "Hello", fill = "yellow", fill_style = "solid") exc_ellipse(200, 0, 120, 80, fill = "#a5d8ff", fill_style = "hachure") exc_diamond(360, 0, 120, 100, rounded = TRUE)
Applies a preset (or individual settings) to every element: sloppiness, stroke width, handwriting font, fill style and ink colour. Dark strokes and text become the preset's ink colour; coloured strokes are kept.
exc_restyle(scene, preset = "whiteboard", ...)exc_restyle(scene, preset = "whiteboard", ...)
scene |
An |
preset |
A preset name or |
... |
Settings to override: |
The restyled scene. The paper is remembered for exc_save() and
plot().
s <- exc_scene(exc_rect(0, 0, 120, 60, label = "hi", fill = "blue")) exc_restyle(s, "chalkboard")s <- exc_scene(exc_rect(0, 0, 120, 60, label = "hi", fill = "blue")) exc_restyle(s, "chalkboard")
Renders the scene offline with the native renderer (rough.js in V8 plus grid) and saves it. The file type follows the extension:
.png, .jpg: bitmap via ragg, with the handwriting fonts.
.svg: vector via svglite, with the fonts embedded so the file looks
the same everywhere.
.pdf: vector via cairo, with text drawn as outlines.
exc_save( scene, file, scale = 1, padding = 10, background = TRUE, paper = NULL, text = c("auto", "outline", "font"), engine = c("native", "excalidraw"), embed_scene = grepl("\\.excalidraw\\.(svg|png)$", tolower(file)) )exc_save( scene, file, scale = 1, padding = 10, background = TRUE, paper = NULL, text = c("auto", "outline", "font"), engine = c("native", "excalidraw"), embed_scene = grepl("\\.excalidraw\\.(svg|png)$", tolower(file)) )
scene |
An |
file |
Output path. |
scale |
Pixel density: 1 = one image pixel per scene px, 2 for sharper "retina" images. For vector formats it scales the page size. |
padding |
Space around the drawing, in px. |
background |
Draw the background colour ( |
paper |
Optional paper background; see |
text |
Text drawing mode; see |
engine |
|
embed_scene |
For SVG and PNG, also store the scene inside the image
so it can be reopened as an editable drawing (like Excalidraw's "Embed
scene" export). On by default for |
file, invisibly.
s <- exc_scene(exc_ellipse(0, 0, 120, 80, label = "sketchy!", fill = "blue", fill_style = "hachure")) f <- tempfile(fileext = ".png") exc_save(s, f, scale = 2)s <- exc_scene(exc_ellipse(0, 0, 120, 80, label = "sketchy!", fill = "blue", fill_style = "hachure")) f <- tempfile(fileext = ".png") exc_save(s, f, scale = 2)
A scene holds elements (shapes, text, arrows, images, frames), the
canvas settings (appState) and any embedded image files. It is stored
exactly as Excalidraw's JSON, so reading and writing files loses nothing.
exc_scene(..., background = "#ffffff", app_state = list())exc_scene(..., background = "#ffffff", app_state = list())
... |
Elements: results of |
background |
Canvas background colour. |
app_state |
Extra |
An exc_scene object.
scene <- exc_scene( exc_rect(0, 0, 160, 80, label = "Idea", fill = "yellow"), exc_arrow(c(160, 260), c(40, 40)), exc_ellipse(260, 0, 140, 80, label = "Chart") ) scenescene <- exc_scene( exc_rect(0, 0, 160, 80, label = "Idea", fill = "yellow"), exc_arrow(c(160, 260), c(40, 40)), exc_ellipse(260, 0, 140, 80, label = "Chart") ) scene
Useful for the input$<id>_scene value sent by the editor in Shiny.
exc_scene_from_json(json)exc_scene_from_json(json)
json |
A JSON string in Excalidraw's file format. |
An exc_scene.
Set the default style for new elements
exc_set_style(...)exc_set_style(...)
... |
Style properties, as in |
Invisibly, the previous default style.
old <- exc_set_style(roughness = "cartoonist", stroke = "blue") exc_set_style() # back to defaultsold <- exc_set_style(roughness = "cartoonist", stroke = "blue") exc_set_style() # back to defaults
Prints a rendered reveal.js presentation (HTML) to PDF with headless Chrome, one slide per page. Needs the chromote package.
exc_slides_pdf(html, output = sub("\\.html?$", ".pdf", html), wait = 3)exc_slides_pdf(html, output = sub("\\.html?$", ".pdf", html), wait = 3)
html |
The rendered slides ( |
output |
PDF path. |
wait |
Seconds to let the slides (and their hand-drawn marks) finish drawing before printing. |
output, invisibly.
scratchy bundles a dozen community libraries from https://libraries.excalidraw.com (all MIT licensed): R and RStudio icons, stick figures, storytelling faces, speech bubbles, sticky notes, stars, hearts, emojis, data-viz icons, hand-drawn signs, general icons and data-science logos. They arrive as native Excalidraw elements, so they are hand-drawn, recolourable and editable.
exc_stickers(library = NULL) exc_sticker(scene, sticker, x = 0, y = 0, width = NULL, ..., panel = 1) exc_sticker_sheet(library, columns = 6)exc_stickers(library = NULL) exc_sticker(scene, sticker, x = 0, y = 0, width = NULL, ..., panel = 1) exc_sticker_sheet(library, columns = 6)
library |
Library name, such as |
scene |
An |
sticker |
|
x, y
|
Where to put the sticker's top-left corner. Data values work
for scenes made from a ggplot; px otherwise (or in |
width |
Width to scale the sticker to, in px. |
... |
Style properties to apply to every element of the sticker,
such as |
panel |
Panel number for faceted plots. |
columns |
Number of columns in the preview grid. |
exc_stickers() lists them; exc_sticker_sheet() draws a numbered
preview of one library.
exc_sticker() adds one to a scene.
exc_peep() adds a hand-drawn person from Open Peeps.
read_excalidraw_lib() and exc_library_item() work with any other
library file.
exc_stickers(): a data frame with one row per sticker
(library, item, name, sticker). Use the sticker column with
exc_sticker().
exc_sticker_sheet(): a scene with every sticker of the library
and its number; draw it with plot().
head(exc_stickers()) exc_stickers("stick-figures")head(exc_stickers()) exc_stickers("stick-figures")
A style is a set of element properties (stroke colour, fill, sloppiness, and
so on). Pass one to any element constructor with style =, or set a
session default with exc_set_style(). Arguments given directly to a
constructor override the style.
exc_style( stroke = NULL, fill = NULL, fill_style = NULL, stroke_width = NULL, stroke_style = NULL, roughness = NULL, opacity = NULL, font = NULL, font_size = NULL )exc_style( stroke = NULL, fill = NULL, fill_style = NULL, stroke_width = NULL, stroke_style = NULL, roughness = NULL, opacity = NULL, font = NULL, font_size = NULL )
stroke |
Stroke (and text) colour: a hex colour, an R colour name, or
an Excalidraw hue name such as |
fill |
Background fill colour, or |
fill_style |
|
stroke_width |
A number, or |
stroke_style |
|
roughness |
Sloppiness: a number, or |
opacity |
Opacity from 0 to 100. |
font |
Font name (see |
font_size |
Font size in px. Excalidraw's presets are 16, 20, 28 and 36. |
A list of class exc_style.
exc_style(stroke = "blue", fill = "blue", fill_style = "hachure")exc_style(stroke = "blue", fill = "blue", fill_style = "hachure")
A KPI card with {{metric}}, {{value}} and {{change}} text and a
{{chart:trend}} slot, for trying exc_template_fill(). Write it out
with write_excalidraw() to open it in Excalidraw and make it your own.
exc_template_example()exc_template_example()
An exc_scene.
Design a card, poster or slide in Excalidraw, with placeholders in the text, and fill it from R:
{{column}} in any text is replaced by that value.
A shape whose label is {{chart:name}} gets a sketched chart drawn to
fit inside it (a ggplot, or a function of the data row returning one).
A shape whose label is {{image:name}} gets an image file fitted
inside it.
exc_template_fill(template, data = list(), charts = list(), images = list()) exc_template_render( template, data, dir = ".", file = "card-{.row}.png", charts = list(), images = list(), ... )exc_template_fill(template, data = list(), charts = list(), images = list()) exc_template_render( template, data, dir = ".", file = "card-{.row}.png", charts = list(), images = list(), ... )
template |
An |
data |
A named list or a one-row data frame of values. |
charts |
A named list of charts: ggplots, scenes, or functions that take the data row and return one. |
images |
A named list of image file paths (or functions of the row).
Values in |
dir |
Folder to write the files to. |
file |
File name pattern. |
... |
Options passed to |
exc_template_fill() fills one copy; exc_template_render() fills and
saves one image (or .excalidraw file) per row of a data frame.
exc_template_fill(): the filled exc_scene.
exc_template_render(): the file paths, invisibly.
card <- exc_template_fill( exc_template_example(), data = list(metric = "Sketches drawn", value = "1,204", change = "+18% this month"), charts = list(trend = ggplot2::ggplot(data.frame(x = 1:12, y = cumsum(rnorm(12))), ggplot2::aes(x, y)) + ggplot2::geom_line()) ) plot(card)card <- exc_template_fill( exc_template_example(), data = list(metric = "Sketches drawn", value = "1,204", change = "+18% this month"), charts = list(trend = ggplot2::ggplot(data.frame(x = 1:12, y = cumsum(rnorm(12))), ggplot2::aes(x, y)) + ggplot2::geom_line()) ) plot(card)
Text
exc_text( text, x, y, ..., hjust = 0, vjust = 0, text_align = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL )exc_text( text, x, y, ..., hjust = 0, vjust = 0, text_align = NULL, style = NULL, angle = 0, group = NULL, id = NULL, custom = NULL )
text |
The text. Use |
x, y
|
Position of the anchor point in px. |
... |
Style properties: |
hjust, vjust
|
Where the anchor sits on the text box: 0 = left/top, 0.5 = centre, 1 = right/bottom. |
text_align |
|
style |
An |
angle |
Rotation in degrees, clockwise, around the shape's centre. |
group |
Group id(s) to put the element in. See |
id |
Element id. Generated if |
custom |
A list stored in the element's |
An exc_elements object.
exc_text("Hand-drawn!", 100, 50, font_size = 28, hjust = 0.5)exc_text("Hand-drawn!", 100, 50, font_size = 28, hjust = 0.5)
Move or scale a whole scene
exc_translate(scene, dx = 0, dy = 0, scale = 1)exc_translate(scene, dx = 0, dy = 0, scale = 1)
scene |
An |
dx, dy
|
Offset in px. |
scale |
Scale factor applied around the scene's top-left corner (after moving). Sizes, points and font sizes scale; stroke widths stay the same. |
The transformed object.
Shows a scene in the real Excalidraw editor, in the RStudio viewer, a
browser, R Markdown/Quarto HTML or a Shiny app. In "edit" mode you can
draw, annotate and restyle; in Shiny the edited scene comes back as
input$<id>_scene (see excalidrawOutput()).
excalidraw( scene = exc_scene(), mode = c("edit", "view"), theme = c("light", "dark"), grid = FALSE, zen = FALSE, width = NULL, height = NULL, elementId = NULL, debounce = 400, extras = TRUE )excalidraw( scene = exc_scene(), mode = c("edit", "view"), theme = c("light", "dark"), grid = FALSE, zen = FALSE, width = NULL, height = NULL, elementId = NULL, debounce = 400, extras = TRUE )
scene |
An |
mode |
|
theme |
|
grid |
Show the grid. |
zen |
Zen mode: hide most of the toolbar. |
width, height
|
Widget size (CSS units or pixels). |
elementId |
Optional element id. |
debounce |
Milliseconds to wait after the last edit before sending the scene to Shiny. |
extras |
Add the scratchy sidebar (the button next to Library):
the bundled sticker libraries, Open Peeps people, the style presets of
|
The editor and its fonts are bundled with the package, so it works
offline. Because the bundle is a JavaScript module made of several files,
save it with htmlwidgets::saveWidget(w, file, selfcontained = FALSE).
An htmlwidget.
if (interactive()) { excalidraw(exc_scene(exc_rect(0, 0, 160, 80, label = "Edit me!", fill = "yellow"))) }if (interactive()) { excalidraw(exc_scene(exc_rect(0, 0, 160, 80, label = "Edit me!", fill = "yellow"))) }
Excalidraw's palette is built on Open Color. Each hue has five shades, from very light (1) to strong (5). Excalidraw uses shade 5 for strokes and shade 2 for fills.
excalidraw_colors(type = c("stroke", "background", "all"), n = NULL)excalidraw_colors(type = c("stroke", "background", "all"), n = NULL)
type |
|
n |
Number of colours to return. Colours repeat if |
A named character vector of hex colours, or a data frame for
type = "all".
excalidraw_colors("stroke", 4) excalidraw_colors("background", 4) head(excalidraw_colors("all"))excalidraw_colors("stroke", 4) excalidraw_colors("background", 4) head(excalidraw_colors("all"))
Create a proxy for an excalidrawOutput() and send it commands without
re-rendering the editor (so hand-drawn changes are kept).
excalidraw_proxy(outputId, session = shiny::getDefaultReactiveDomain()) exc_proxy_update(proxy, scene, keep_app_state = FALSE) exc_proxy_add(proxy, scene, placement = c("as-is", "right")) exc_proxy_replace_chart(proxy, scene, chart = "chart") exc_proxy_scroll_to(proxy) exc_proxy_set( proxy, theme = NULL, view_mode = NULL, zen = NULL, grid = NULL, background = NULL ) exc_proxy_reset(proxy) exc_proxy_export(proxy, type = c("png", "svg"), embed = FALSE, scale = 2) exc_proxy_mermaid(proxy, code, font_size = 20)excalidraw_proxy(outputId, session = shiny::getDefaultReactiveDomain()) exc_proxy_update(proxy, scene, keep_app_state = FALSE) exc_proxy_add(proxy, scene, placement = c("as-is", "right")) exc_proxy_replace_chart(proxy, scene, chart = "chart") exc_proxy_scroll_to(proxy) exc_proxy_set( proxy, theme = NULL, view_mode = NULL, zen = NULL, grid = NULL, background = NULL ) exc_proxy_reset(proxy) exc_proxy_export(proxy, type = c("png", "svg"), embed = FALSE, scale = 2) exc_proxy_mermaid(proxy, code, font_size = 20)
outputId |
The editor's output id. |
session |
The Shiny session. |
proxy |
A proxy from |
scene |
A scene, elements, or anything |
keep_app_state |
Keep the editor's current canvas settings. |
placement |
|
chart |
A name for the chart. Elements from an earlier call with the same name are replaced (in the same place); everything else stays. |
theme, view_mode, zen, grid, background
|
Editor settings to change. |
type |
Export format, |
embed |
Embed the scene in the image so it stays editable. |
scale |
PNG pixel density. |
code |
Mermaid diagram text, such as |
font_size |
Font size for the diagram text. |
excalidraw_proxy() returns a proxy object; the other functions
return the proxy invisibly, so they can be piped.
## Not run: server <- function(input, output, session) { output$canvas <- renderExcalidraw(excalidraw()) observeEvent(input$add_note, { excalidraw_proxy("canvas") |> exc_proxy_add(exc_rect(0, 0, 160, 80, label = "New note", fill = "yellow")) }) } ## End(Not run)## Not run: server <- function(input, output, session) { output$canvas <- renderExcalidraw(excalidraw()) observeEvent(input$add_note, { excalidraw_proxy("canvas") |> exc_proxy_add(exc_rect(0, 0, 160, 80, label = "New note", fill = "yellow")) }) } ## End(Not run)
Output and render functions for the excalidraw() widget. The widget
reports back to the server as:
input$<outputId>_scene: the scene as Excalidraw JSON, shortly after
each edit. Turn it into a scene with exc_scene_from_json().
input$<outputId>_selection: ids of the selected elements.
input$<outputId>_export: the result of exc_proxy_export().
input$<outputId>_mermaid: whether a exc_proxy_mermaid() call worked.
excalidrawOutput(outputId, width = "100%", height = "600px") renderExcalidraw(expr, env = parent.frame(), quoted = FALSE)excalidrawOutput(outputId, width = "100%", height = "600px") renderExcalidraw(expr, env = parent.frame(), quoted = FALSE)
outputId |
Output id. |
width, height
|
Size of the editor. |
expr |
An expression that returns an |
env, quoted
|
Standard htmlwidgets arguments. |
A Shiny output or render function.
Reads Excalidraw JSON files (.excalidraw, .json), Obsidian drawings
(.excalidraw.md), and SVG or PNG images with an embedded scene (such as
Excalidraw exports made with "Embed scene", or files from
write_excalidraw()).
read_excalidraw(path)read_excalidraw(path)
path |
File path. |
An exc_scene.
Libraries (.excalidrawlib files) are collections of reusable drawings,
such as the ones at https://libraries.excalidraw.com.
read_excalidraw_lib() returns the items; exc_library_item() places one
in a scene; write_excalidraw_lib() saves elements as a library.
read_excalidraw_lib(path) write_excalidraw_lib(items, path) exc_library_item(library, item, x = 0, y = 0, width = NULL)read_excalidraw_lib(path) write_excalidraw_lib(items, path) exc_library_item(library, item, x = 0, y = 0, width = NULL)
path |
File path. |
items |
A named list of |
library |
An |
item |
Item number or name. |
x, y
|
Where to put the item's top-left corner, in px. |
width |
Optional width to scale the item to. |
read_excalidraw_lib(): a list of items, each with a name and
elements.
Called automatically when the package loads. Registered fonts work on
devices that use 'systemfonts', such as ragg::agg_png() and
svglite::svglite(). Other devices (for example grDevices::pdf()) get
text drawn as glyph outlines by the native renderer instead.
register_fonts()register_fonts()
Invisibly, the names of the registered font families.
A Shiny app built on scratchy:
Data: pick a built-in dataset, upload a CSV or paste from a spreadsheet.
Chart: choose a chart type and what goes on each axis.
Style: preset, sloppiness, fill, font, grid, and a new wobble.
Add: sticky notes, stickers, hand-drawn people and Mermaid diagrams, straight onto the canvas.
Templates: fill an Excalidraw template from a CSV, one image per row.
Export: PNG, SVG, PDF, .excalidraw, Obsidian .excalidraw.md, an
editable .excalidraw.svg, and the R code that recreates the chart.
run_sketch_studio(..., launch.browser = interactive())run_sketch_studio(..., launch.browser = interactive())
... |
Options passed to |
launch.browser |
Open the app in a browser. |
The canvas is the real Excalidraw editor: draw, move and annotate freely. Changing chart settings swaps only the chart; your drawing stays.
A Shiny app object; printing it (or calling the function at the console) runs the app.
if (interactive()) run_sketch_studio()if (interactive()) run_sketch_studio()
Discrete scales use Excalidraw's palette: light fills for fill, strong
colours for colour. The continuous versions run through the five shades
of one hue.
scale_fill_excalidraw(..., type = c("background", "stroke")) scale_colour_excalidraw(..., type = c("stroke", "background")) scale_color_excalidraw(..., type = c("stroke", "background")) scale_fill_excalidraw_c(..., hue = "blue") scale_colour_excalidraw_c(..., hue = "blue")scale_fill_excalidraw(..., type = c("background", "stroke")) scale_colour_excalidraw(..., type = c("stroke", "background")) scale_color_excalidraw(..., type = c("stroke", "background")) scale_fill_excalidraw_c(..., hue = "blue") scale_colour_excalidraw_c(..., hue = "blue")
... |
Passed to the underlying ggplot2 scale. |
type |
For the discrete scales, |
hue |
For the continuous scales, an Excalidraw hue such as |
A ggplot2 scale.
library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() + scale_fill_excalidraw() sketch(p)library(ggplot2) p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() + scale_fill_excalidraw() sketch(p)
sketch() wraps a plot so that printing it converts it with
as_excalidraw() and draws the result with the native renderer. The plot
is laid out at the size of the device it is drawn on, so it works in the
RStudio plot pane, in knitr/Quarto chunks, and with
ggplot2::ggsave("plot.png", sketch(p), width = 7, height = 4).
sketch( plot, ..., preset = NULL, paper = NULL, background = TRUE, width = NULL, height = NULL )sketch( plot, ..., preset = NULL, paper = NULL, background = TRUE, width = NULL, height = NULL )
plot |
A ggplot, a formula such as |
... |
Options passed to |
preset |
Optional |
paper |
Optional paper background; see |
background |
Draw the background colour; |
width, height
|
Fixed layout size in px. By default the device size is used. |
An exc_sketch object. Print it to draw it, or turn it into a
scene with as_excalidraw().
library(ggplot2) p <- ggplot(mpg, aes(displ, hwy, colour = drv)) + geom_point(size = 3) + scale_colour_excalidraw() sketch(p) sketch(p, preset = "chalkboard") sketch(~ barplot(VADeaths, beside = TRUE))library(ggplot2) p <- ggplot(mpg, aes(displ, hwy, colour = drv)) + geom_point(size = 3) + scale_colour_excalidraw() sketch(p) sketch(p, preset = "chalkboard") sketch(~ barplot(VADeaths, beside = TRUE))
A clean, whiteboard-like theme: handwriting font, ink-coloured axis lines
and ticks, no grey panel, and text sizes that land on Excalidraw's own
font sizes (16, 20 and 28 px at the default base_size). It works with
plain ggplot2 output and is the default theme used by as_excalidraw()
and sketch(). It also pairs well with sketchy geoms from other packages
such as ggsketch.
theme_excalidraw( base_size = 15, base_family = "Excalifont", ink = "#1e1e1e", grid = c("none", "y", "x", "xy"), background = "white", preset = NULL )theme_excalidraw( base_size = 15, base_family = "Excalifont", ink = "#1e1e1e", grid = c("none", "y", "x", "xy"), background = "white", preset = NULL )
base_size |
Base font size in points. 15 pt = 20 px, Excalidraw's default. |
base_family |
Font family; see |
ink |
Colour for text, axes and ticks. |
grid |
Which grid lines to draw: |
background |
Plot background colour, or |
preset |
Optional |
The handwriting fonts are registered with 'systemfonts', so a plot printed
directly with this theme needs a device that uses it: ragg (in RStudio,
set Tools > Global Options > Graphics > Backend to "AGG") or svglite.
sketch() works on every device because it draws text as outlines.
A ggplot2 theme.
library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") + theme_excalidraw(grid = "y") sketch(p, theme = NULL)library(ggplot2) p <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") + theme_excalidraw(grid = "y") sketch(p, theme = NULL)
Sets up a Quarto presentation that uses the excalidraw-revealjs format:
Excalifont headings, Excalidraw colours, sketchy code blocks and
callouts, and figures sized for slides. In the slides you can use:
[text]{.rn-underline}, .rn-circle, .rn-box, .rn-highlight,
.rn-strike, .rn-cross and .rn-bracket for hand-drawn marks
(add .fragment to reveal them on click);
[text]{.sticky-note} (also .blue, .pink, .green);
::: {.sketch-box} for a box with a rough border (data-fill adds a
hachure fill);
excalidraw: paper: in the YAML (dots, graph, lines, kraft,
blueprint, chalkboard);
sketch() and plot() of scenes in R chunks.
use_excalidraw_slides(path = "slides", file = "slides.qmd", overwrite = FALSE)use_excalidraw_slides(path = "slides", file = "slides.qmd", overwrite = FALSE)
path |
Folder for the presentation. Created if needed. |
file |
Name of the slides file. |
overwrite |
Replace existing files. |
The path of the slides file, invisibly.
## Not run: use_excalidraw_slides("talk") # then: quarto render talk/slides.qmd ## End(Not run)## Not run: use_excalidraw_slides("talk") # then: quarto render talk/slides.qmd ## End(Not run)
The format follows the file extension:
.excalidraw or .json: Excalidraw's JSON format, for excalidraw.com
and the VS Code extension.
.excalidraw.md: a drawing for the Obsidian Excalidraw plugin. Images
are saved in a folder next to it.
.excalidraw.svg, .excalidraw.png (or any .svg / .png): a
rendered image with the scene embedded, so it can be opened again as an
editable drawing in excalidraw.com, VS Code or with read_excalidraw().
write_excalidraw(scene, path, pretty = TRUE, compress = TRUE, ...)write_excalidraw(scene, path, pretty = TRUE, compress = TRUE, ...)
scene |
An |
path |
File path. |
pretty |
Indent the JSON (JSON and Obsidian files). |
compress |
For Obsidian files, store the drawing compressed, as the plugin does by default. |
... |
For images, options passed to |
path, invisibly.
s <- exc_scene(exc_rect(0, 0, 100, 60, label = "hi")) f <- tempfile(fileext = ".excalidraw") write_excalidraw(s, f) read_excalidraw(f) # an image that stays editable f2 <- tempfile(fileext = ".excalidraw.png") write_excalidraw(s, f2, scale = 2) read_excalidraw(f2)s <- exc_scene(exc_rect(0, 0, 100, 60, label = "hi")) f <- tempfile(fileext = ".excalidraw") write_excalidraw(s, f) read_excalidraw(f) # an image that stays editable f2 <- tempfile(fileext = ".excalidraw.png") write_excalidraw(s, f2, scale = 2) read_excalidraw(f2)