sketch() draws any plot in Excalidraw style, at the size
of whatever device it lands on, so it works in the plot pane, in knitr
chunks and with ggsave().
p <- ggplot(mpg, aes(class, fill = drv)) + geom_bar() +
scale_fill_excalidraw() + labs(title = "Drive train by class", x = NULL)
sketch(p)as_excalidraw() returns the scene itself, ready to
annotate, restyle, save or open in Excalidraw:
By default plots get theme_excalidraw() (handwriting
font, ink axes, no grey panel). Pass theme = NULL to keep
your own theme. Other options: fill_style,
roughness, font, outline,
preset and seed.
Scenes made from a ggplot remember how data values map to positions,
so annotations can point at the data. Categories map to their centre;
wrap a number in I() to give pixels instead.
cars <- ggplot(mpg, aes(class)) + geom_bar(fill = "#a5d8ff") + labs(x = NULL, y = "cars")
as_excalidraw(cars) |>
exc_title("What do people drive?") |>
exc_mark(x = "suv", y = c(0, 62), type = "box") |>
exc_mark(x = "compact", y = 47, type = "circle") |>
exc_note("SUVs win!", x = "midsize", y = 52, to = c("suv", 50)) |>
exc_callout("only 5 of these", x = "2seater", y = 5, dx = 30, dy = -70) |>
plot()exc_mark() types: "circle",
"box", "underline", "highlight",
"strike", "bracket", "cross".
excalidraw_colors("stroke", 6)
#> [1] "#1971c2" "#e03131" "#2f9e44" "#f08c00" "#9c36b5" "#0c8599"
excalidraw_colors("background", 6)
#> [1] "#a5d8ff" "#ffc9c9" "#b2f2bb" "#ffec99" "#eebefa" "#99e9f2"scale_fill_excalidraw() uses the light fills and
scale_colour_excalidraw() the strong strokes; the
_c versions run through the shades of one hue.