Reputation: 3494
I don't know much about graphic devices etc. All I want to do is to save plots to PDF and to embed fonts.
I use cairo_pdf()
for this, but I noticed that sometimes plot elements are printed outside of the box/plot region (see screenshots of the PDFs). I can reproduce the issue on different Windows machines, different R versions, using packages cairoDevice or Cairo, and with for example lines()
. But plots saved via pdf()
look fine.
My questions are:
cairo_pdf()
-plots look different compared to pdf()
-plots? Are there any other disadvantages of using cairo_pdf()
?Below are screenshots from details of the whole PDFs illustrating the differences. Note that, in the left image, the axis overlap with some points.
capabilities("cairo")
#> cairo
#> TRUE
set.seed(123456)
N <- 10000
v1 <- rnorm(N)
v2 <- rnorm(N)
v3 <- ifelse(v1 > 1.02 | v2 > 1.02 | v1 < -.02 | v2 < -.02, 2, 1)
cairo_pdf("plot1.pdf")
plot(v1, v2, xlim = 0:1, ylim = 0:1, col = v3, pch = 16)
dev.off()
#> null device
#> 1
pdf("plot2.pdf")
plot(v1, v2, xlim = 0:1, ylim = 0:1, col = v3, pch = 16)
dev.off()
#> null device
#> 1
devtools::session_info()
#> Session info ------------------------------------------------------------------
#> setting value
#> version R version 3.4.2 (2017-09-28)
#> system x86_64, mingw32
#> ui Rgui
#> language (EN)
#> collate German_Germany.1252
#> tz Europe/Berlin
#> date 2018-03-09
#>
#> Packages ----------------------------------------------------------------------
#> package * version date source
#> base * 3.4.2 2017-09-28 local
#> compiler 3.4.2 2017-09-28 local
#> datasets * 3.4.2 2017-09-28 local
#> devtools 1.13.5 2018-02-18 CRAN (R 3.4.3)
#> digest 0.6.15 2018-01-28 CRAN (R 3.4.3)
#> graphics * 3.4.2 2017-09-28 local
#> grDevices * 3.4.2 2017-09-28 local
#> memoise 1.1.0 2017-04-21 CRAN (R 3.4.1)
#> methods * 3.4.2 2017-09-28 local
#> stats * 3.4.2 2017-09-28 local
#> utils * 3.4.2 2017-09-28 local
#> withr 2.1.1 2017-12-19 CRAN (R 3.4.3)
Upvotes: 1
Views: 327
Reputation: 3494
This bug is fixed in R 3.6.0.
From the NEWS:
The
cairo_pdf
graphics device (and other Cairo-based devices) now clip correctly to the right and bottom border.
There was an off-by-one-pixel bug, reported by Lee Kelvin.
Upvotes: 3