3 ms·
Then use R's built-in "base graphics". They afford literally pixel-by-pixel control if you know what you're doing, in a 100% declarative API that isn't so hard
by nerdponx 9y ago
Then use R's built-in "base graphics". They afford literally pixel-by-pixel control if you know what you're doing, in a 100% declarative API that isn't so hard to learn.
Building abstractions is just a matter of writing very simple imperative functions. Modifying existing abstractions is a matter of copying and pasting out of the source code for existing ones.
It can involve lots of tedious trial-and-error, and the documentation is a little terse, but it's about as close to drawing by hand as you can get.
Ggplot2 is great for prototyping, but when you want to really own your graphics, go for Base.
There's also a middle path, called Lattice. It's built on the same library as Ggplot2 (called Grid), but lets you dig down into the guts a little more easily, at the cost of your graphs looking "older", since it's based on Trellis graphs from SAS.
- peatmoss 9y agoBase R graphics are a little like Matplotlib in being an organic API. I'd argue that Grid is a better starting point than base R, if you're planning to create a reproducible plot type.
- nerdponx 9y agoOrganic in what sense? Other than "pch" it's much less magical than matplotlib (to me), and its primitives are exposed alongside the convenience functions like hist() with ugly defaults we all love to hate. I will agree on reproducibility and portability across graphics devices (not to mention actoss installations). Grid takes care of so much annoyance in that regard.
- peatmoss 9y agoYeah, the mishmash of convenience functions and pch were pretty much exactly what I was thinking about. Also, I will vehemently agree that base R graphics are still far less magical than matplotlib. So, I guess I meant "like matplotlib, but to a far less extreme degree" :-)
- nerdponx 9y agoI definitely am not a fan of R's inconvenient convenience functions. A saner set of wrappers for R base graphics is on my long to-do list, at least something with better defaults. Someone had started a project that goes in the right direction called "compactr", but it seems abandoned: https://cran.r-project.org/package=compactr https://cran.r-project.org/package=compactr