[Rd] Height not set properly in grDevices::jpeg() with type = "cairo"

Marius marius.mather at gmail.com
Tue Nov 28 04:25:57 CET 2017


Hi,
I have been having issues producing plots in JPEG format, using type =
"cairo" to get better anti-aliasing. When trying to set the physical
size with units = "cm" or units = "mm", the width is set correctly but
the height is not - it looks like the height is simply treated as
pixels regardless of the 'units' argument.

Example:


x = 1:10
y = 2 * x
jpeg("ExamplePlot.jpg",
     type = "cairo",
     width = 200,
     height = 200,
     units = "mm",
     res = 96)
plot(x, y)
dev.off()


On my system (Windows 7, running R 3.4.2), this produces a plot that
is 755 x 200 pixels, and is vertically very squashed.

Looking at grDevices::jpeg, it looks like the culprit is these lines:

   g <- .geometry(width, height, units, res)
    if (match.arg(type) == "cairo") {
        antialias <- match(match.arg(antialias), aa.cairo)
        invisible(.External(C_devCairo, filename, 3L, g$width,
            height, pointsize, bg, res, antialias, quality, if
(nzchar(family)) family else "sans",
            300))
    }

g$width is used, but "height" is used instead of "g$height". I suspect
simply using "g$height" here would fix the issue but have not had time
to test this.

My R.version:

platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
system         x86_64, mingw32
status
major          3
minor          4.2
year           2017
month          09
day            28
svn rev        73368
language       R
version.string R version 3.4.2 (2017-09-28)
nickname       Short Summer

Please let me know if any further information is needed.

Thanks,
Marius



More information about the R-devel mailing list