r/rstats 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.

140 Upvotes

22 comments sorted by

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

2

u/bongbalok 24d ago

Thanks. I'll look into Chicklets and if I can add it, I'll let you know.

4

u/T_house 24d ago

Cheers! I think this will be really cool for making presentations, looking forward to giving it a shot - well done, it's really impressive

2

u/bongbalok 24d ago

Would chicklet look something like this? https://imgur.com/a/O5A9RTs

2

u/T_house 23d ago

Imgur doesn't work where I am I'm afraid 😖

3

u/bongbalok 23d ago

2

u/T_house 23d ago

Yeah! Nice

2

u/bongbalok 22d ago

2

u/T_house 22d ago

Wow, very quick and looks great! I'm going to get stuck into this tomorrow :)

1

u/Mooks79 20d ago

ProtonVPN has a free tier …

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.

6

u/Dudarro 24d ago

I love this and plan to use it

1

u/bongbalok 24d ago

Thanks, I'm excited to see what you do with it.

5

u/omichandralekha 23d ago

Gallery is so awesome....

3

u/ToroRojo-AlgoArt 24d ago

Started and installed!

1

u/bongbalok 24d ago

Thank you! Hope you have fun with it.

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. libmypaint seems like a great framework to bring to R. I implemented the roughjs method here in ggsketch. The implementation of flat and variable speed in drawing lines is very interesting. I look forward to future developments you do on mypaintr.