devoutpdf
is a hand-crafted PDF graphics device written in plain R.
It achieves this by invoking the devout
package to do all the interfacing between the C++ side and the R side.
Drawing commands which sent to the graphics device are used to construct a minipdf
document.
Why would you want this?
Given that pdf()
and cairo_pdf()
devices come with R, what’s the point of a third PDF output device?
- Hacking your own graphics device gives a significant amount of control over the actual output
- You can learn how a graphics device works - it’s just R, so there’s no C++ code to sift through.
- Use as a template to write your own graphics device for something bespoke e.g. pen plotter output or a laser projection driver!
- Glitch the output at the device level e.g. for each line, perhaps draw multiple overlapping lines with randomly jittered endpoints to simulate a ‘pencil sketch’ effect.
The R code
The R code for this device is a single file about 300 lines long - most of which is whitespace and comments. Check it out on github
ToDo
- Helvetica font is currently used regardless of what the user specifies. This is a deficiency that first needs to be fixed in
minipdf
.
Installation
You can install from GitHub with:
Example: ggplot scatterplot
Example: ggplot density plot
Example: base graphics pie chart