Home

Awesome

<!-- README.md is generated from README.Rmd. Please edit that file -->

devoutpdf <img src="man/figures/logo.png" align="right" height=230/>

<!-- badges: start -->

<!-- badges: end -->

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?

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

Installation

You can install from GitHub with:

# install.packages("devtools")
devtools::install_github("coolbutuseless/devout")    # graphics device shim
devtools::install_github("coolbutuseless/minipdf")   # PDF document builder
devtools::install_github("coolbutuseless/devoutpdf") # Devout PDF graphics device

Example: ggplot scatterplot

devoutpdf::pdfout(filename = "man/figures/test1.pdf", width=5, height=4)
ggplot(mtcars) + 
  geom_point(aes(mpg, wt)) + 
  labs(title = "test1") + 
  theme_bw()
invisible(dev.off())
<img src="man/figures/test1.png" width="70%" />

Example: ggplot bar plot

devoutpdf::pdfout(filename = "man/figures/test2.pdf", width = 6, height = 4)
ggplot(mtcars) + 
  geom_bar(aes(as.factor(cyl), fill = as.factor(cyl))) + 
  labs(title = "test2")
invisible(dev.off())
<img src="man/figures/test2.png" width="100%" />

Example: ggplot density plot

devoutpdf::pdfout(filename = "man/figures/test3.pdf", width = 6, height = 4)
ggplot(mtcars) + 
  geom_density(aes(mpg, fill = as.factor(cyl)), alpha = 1, size = 2) +
  theme_bw()
invisible(dev.off())
<img src="man/figures/test3.png" width="100%" />

Example: tmap world plot

library(tmap)
data("World")

devoutpdf::pdfout(filename = "man/figures/test4.pdf", width = 5, height = 4)
tm_shape(World) +
    tm_polygons("HPI")
invisible(dev.off())
<img src="man/figures/test4.png" width="100%" />

Example: base graphics pie chart

devoutpdf::pdfout(filename = "man/figures/test5.pdf", width = 5, height = 4)
pie(c(cool = 4, but = 2, use = 1, less = 8))
invisible(dev.off())
<img src="man/figures/test5.png" width="100%" />