Search code examples
rpdfr-forestplot

Saving an extremely long figure as pdf in R will cause all text invisible


R 4.2.1 package usage: netmeta 2.8-1

Issue: In netmeta package, the function forest() will create a forest plot. One need to know that forest() can generate a forest plot presenting the network inconsistency between direct and indirect comparisons.

In my case, I have an extremely large network, which will lead to more than 2000 comparisons. The forest plot describing network inconsistency will be VERY long in height.

The following script can only create "part" of the forest because the forest is too long.

pdf("filename.pdf",width = 12, height = 200)
forest(out, show = "all")
dev.off()

I tried to increase the height to make all the content in this document. But any value above 200 in height will generate a "blank" pdf (but I think the text should be there because the file size is 240KB rather than a NULL file which only takes 4KB in my disk).

I have no idea how to make the text visible in pdf and keep all content in this file at the same time. Any suggestion will be appreciated. Thank you.


Solution

  • PDF 1.x has an implementation limit for the page size:

    The minimum page size should be 3 by 3 units in default user space; the maximum should be 14,400 by 14,400 units. In versions of PDF earlier than 1.6, the size of the default user space unit was fixed at 1⁄72 inch, yielding a minimum of approximately 0.04 by 0.04 inch and a maximum of 200 by 200 inches. Beginning with PDF 1.6, the size of the unit may be set on a page-by-page basis; the default remains at 1/72 inch.

    (ISO 32000-1, Annex C.2 Architectural limits)

    If R doesn't adjust the default user space unit size in case of large width or height arguments, it generates PDFs that go beyond these limits whenever you set either argument to a value greater than 200.

    As those limits originate from the Adobe implementation of the PDF spec, i.e. Adobe Acrobat, tests with Adobe software may indeed show issues...