R-package icon indicating copy to clipboard operation
R-package copied to clipboard

Plotmath greek characters render differently depending on plot device

Open dkStevensNZed opened this issue 10 months ago • 2 comments

A quirky little issue this. Using quarto/pdf, I created a plot with plotmath greek character mu $\mu$ in the y label. In rendering to pdf, if the chunk's dev is not selected {r}, the greek mu is rendered as a proportional symbol ($\propto$). If I use {r,dev='cairo_pdf'} , mu renders correctly. The same code in pure R (executed from the console) shows properly. Here's a MWE in quarto. I hope this is a known issue. Any help is welcome.

`--- format: pdf

{r} #| echo: false #| message: false #| fig-cap: myCap #| fig-height: 3.5 #| fig-width: 5. #| out-width: 5.in x <- rnorm(20,0,1) plot(x, xlab='x var', ylab=expression(paste('The Greek Letter mu (', mu, ')')))

{r,dev='cairo_pdf'} #| echo: false #| message: false #| fig-cap: myCap2 #| fig-height: 3.5 #| fig-width: 5. #| out-width: 5.in plot(x, xlab='x var', ylab=expression(paste('The Greek Letter mu (', mu, ')'))) `

dkStevensNZed avatar Apr 09 '24 16:04 dkStevensNZed

Hi @dkStevensNZed

Thanks for this issue.

Unicode plotting in R is a sad mess -.- There was an issue where Cran did a crack down recently: https://github.com/project-gen3sis/R-package/issues/66

I'm pretty sure the default printing also depends on your locale and language settings.

Iirc we tried using cairo_pdf, but it did not play well with other parts of the plotting code... or I didn't have the time to fully convert all plotting :man_shrugging: we may revisit this topic at some point

Are you asking for help, or was this just a comment on how you solved the issue?

cheers

benj919 avatar Apr 17 '24 07:04 benj919

Thanks for the update. Kinda both - asking for help and the comment on the approach to use if ever one needs to avoids these circumstances. I haven't tried all possibilities, only noticed that 'mu' becomes 'proportion' but beta renders correctly. I haven't noticed other issues with cairo_pdf. What should I be looking out for?

dkStevensNZed avatar Apr 21 '24 13:04 dkStevensNZed