8000 PNG forest plots are clipped on Linux when saved with default sizing · Issue #115 · guido-s/meta · GitHub
[go: up one dir, main page]

Skip to content

PNG forest plots are clipped on Linux when saved with default sizing #115

Backlog

Description

@NourEdinDarwish

Hi,

This is unrelated to meta 9.0-0, just something I noticed earlier and wanted to report.

When saving the same forest plot as PDF and PNG using forest(..., filename = ...) with default sizing, the PNG is clipped on Linux while the PDF fits. Windows and macOS outputs look fine.

This happens because forest_dims_internal() measures the plot on pdf(file = NULL) using Helvetica AFM font metrics (and forest_dims() itself creates a temporary .pdf), regardless of the target format. When ragg is installed, PNG output uses ragg::agg_png(). On Windows and macOS, ragg uses Arial / Helvetica (close to PDF's Helvetica AFM), whereas on Linux it resolves sans to the wider DejaVu Sans font, making the measured width too narrow. Because each device resolves fonts differently, setting fontfamily alone does not fix this; measurement needs to run on the actual output device.

Here is a small reproduction repository with GitHub Actions results across all three OSes (each artifact contains the PDF and PNG):

Would it be possible to let forest_dims() accept a measurement device (with the same font settings as the plot), and have forest(..., filename = ...) measure on the selected output device when autosizing?

grid::grid.grabExpr() already accepts a device function and notes in its documentation that the default PDF device is unsuitable for custom fonts:

https://stat.ethz.ch/R-manual/R-devel/library/grid/html/grid.grab.html

Devices like pdf(file = NULL) and ragg::agg_record() allow measuring without writing a file, and a temporary file works for devices without an in-memory recorder.

I'd be happy to help implement this in a PR if you think it's useful.

Thanks!

Activity

  1. guido-s commented on Dec 3, 2026

    @guido-s
    Owner

    @NourEdinDarwish Thank you for pointing this out. I would definitely be interested in fixing this issue, so a PR would be very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0