aphalo / ggpmisc

R package ggpmisc is an extension to ggplot2 and the Grammar of Graphics
https://docs.r4photobiology.info/ggpmisc
96 stars 6 forks source link

Equations not rendering correctly with ggtext::geom_richtext() #13

Closed aphalo closed 1 year ago

aphalo commented 3 years ago

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.

mlaparie commented 2 years ago

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 commented 2 years ago

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.

aphalo commented 2 years ago

@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 commented 2 years ago

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

aphalo commented 1 year ago

Seems to now work correctly.