ggpmisc icon indicating copy to clipboard operation
ggpmisc copied to clipboard

Equations not rendering correctly with ggtext::geom_richtext()

Open aphalo opened this issue 4 years ago • 4 comments

I suspect this is a problem in 'ggtext' rather than 'ggpmisc', but anyway spurious space is inserted where there is not any in eq.label.

aphalo avatar Aug 01 '21 22:08 aphalo

Do you have any workaround in mind for this issue? I observe the same (for spaces and +) when exporting as a png with ggsave():

ss-2022-01-27_171101

It doesn't show up in the R graphics window, just on the exported file. Actually I remember I once got the issue and found another way to export my plot to a file than ggsave(), and it solved the issue, but I cannot find the script where I did that and don't remember at all which command I used.

mlaparie avatar Jan 27 '22 16:01 mlaparie

If that helps troubleshooting, but I understand this is likely an issue external to ggpmisc, exporting to PDF instead of PNG with ggsave(…, device = cairo_pdf) solves the issue:

ss-2022-01-27_172029

[Edit] Well, exporting to PNG works too, you just have to specify the device with ggsave(…, device = png). I find it weird that this doesn't automatically picks that device when using the .png extension, but hey.

mlaparie avatar Jan 27 '22 16:01 mlaparie

@mlaparie In R there are multiple graphic devices for the same type of file output. From package 'ragg' there is agg_png, there is from package 'Cairo', Cairo_png and from R's 'grDevices' built-in package, png. The different devices have different limitations, and most likely ggsave() by default is using a different png device than png. RStudio in the latest versions, I think, uses the 'ragg' devices by default as they are faster. You could test if you get good or bad output with ggsave(..., device = ragg::agg_png).

aphalo avatar Jan 28 '22 23:01 aphalo

TODO: test thoroughly and add suggested workarounds or good 'ggtext' versions.

aphalo avatar Aug 01 '22 10:08 aphalo

Seems to now work correctly.

aphalo avatar Dec 17 '22 16:12 aphalo