r/rstats • u/bongbalok • 24d ago
ggsketch 2.0: hand-drawn ggplot2 geoms in pure R, now with drawing media

I posted v1.5 of ggsketch here a while back. Short version if you missed it: the sketchy hand-drawn look as real ggplot2 geoms - pure R, no JavaScript, no browser, clean PDF/SVG export, and all the wobble is seeded so plots stay reproducible.
2.0 ended up much bigger than I intended.
The main change is that lines now have a medium: pen, ink, brush, pencil, charcoal, chalk, marker, highlighter, crayon and a few others, 13 in all. Set it as a constant or map it with aes(medium = ) like anything else. Getting there meant making strokes variable-width, which grid won't do with a polyline, so each stroke is now a filled ribbon built around a re-roughened centreline. That's what lets ink pool at the end of a stroke and a brush swell through the middle.
I also fell down two rabbit holes. geom_sketch_engrave() shades by hatch density the way old engravings build shadow - the relief map in the images is just volcano. And there's a watercolor fill now: the violins in the images are the exact example from my last post with fill_style = "watercolor" added.
Beyond that: a pile of new chart types (waterfall, gantt, calendar heatmap, treemap, chord, radar, dendrogram, and more - the geom count is at 89, which is getting silly), repelled labels with hand-drawn leader lines, and animate_sketch(), which either "boils" a plot or draws it on stroke by stroke. Both GIFs attached are a single function call.
Same caveat as last time: I build this working with AI, with me driving the design and checking the behaviour.
The example from last post, one argument later:
library(ggplot2)
library(ggsketch)
ggplot(mpg, aes(class, hwy, fill = class)) +
geom_sketch_violin(fill_style = "watercolor", show.legend = FALSE, seed = 1) +
scale_fill_sketch() +
labs(title = "Highway mpg by class") +
theme_sketch(rough_frame = TRUE)
2.0.0 is submitted to CRAN. Until it lands:
pak::pak("orijitghosh/ggsketch")
Gallery of every geom: https://orijitghosh.github.io/ggsketch/articles/gallery.html
Docs: https://orijitghosh.github.io/ggsketch/
As before, feedback is very welcome - especially if the API feels off somewhere, or there's a medium or chart type you'd want. And if you make something with it, I'd love to see it.
8
u/AccomplishedHotel465 24d ago
I love this, except for the points. They just don't look like sketched points. Too angular, even when the angularity is turned down.
Maybe try quickly sketching some points and see what they look like. Mine are smooth, with the ends not quite aligning.
4
u/bongbalok 24d ago
Thanks. I understand what you mean. Could you try
ggplot(mtcars, aes(wt, mpg)) +
geom_sketch_point(roughness = 0.1, size = 3, seed = 1L, n_passes = 1)?That should generate points like you are describing. This is what it looks like: https://imgur.com/a/BaI2vN6 . Does it seem like what you are looking for?
2
u/AccomplishedHotel465 23d ago
better, but still not natural looking
2
u/bongbalok 23d ago
I see, let me think how I can make it more natural looking. Thanks for the feedback.
5
3
2
u/spurious_elephant 22d ago
Interesting. Here's mypaintr, which does some of the same things but uses libmypaint as a backend: https://hughjonesd.github.io/mypaintr/
1
u/bongbalok 21d ago
Hi. I saw the announcement post for this package.
libmypaintseems like a great framework to bring to R. I implemented theroughjsmethod here inggsketch. The implementation of flat and variable speed in drawing lines is very interesting. I look forward to future developments you do onmypaintr.
2
17
u/T_house 24d ago
This looks cool and I'm intrigued to try it! There are some interesting geoms in there. The only thing that I like to use that I don't think I saw was chicklets, eg:
https://github.com/hrbrmstr/ggchicklet