Rmd dev = pdf ---> accent missing on plot

Hi,

My problem is that I wanted to knit an .Rmd file with the setting dev = 'pdf', to get all the plots in pdf format. The problem is that my language is Hungarian so I would need "ő" charachter in the figure, which is missing.
As an example the legend title "egy főre eső" becomes "egy fore eso".
The problem do not emerge, when dev = "png" or anything else, but I need pdf.

Thank you for your help in advance.

I think you need to play with the argument of pdf() function so that it supports a font with those characters. It uses postscript if I understand well. Graphic devices is not something I find easy.

You could also try other pdf devices

  • the cairo_pdf device from grDevices,
  • or Cairo::CairoPDF()

You could also be interested in this article about how to use fonts with R graphics.

and about the showtext package

https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html

Hope it helps.

If you find the answer, please share.

It may be in fact an encoding issue. If I use the unicode code, it gets printed correclty

pdf()
plot(cars, main = "egy f\u0151re es\u0151")
dev.off()

cairo_pdf solved the issue. Thank you very much!

1 Like

Cool !

It did not in my case but maybe because my French computer is not setup for Hungarian characters. Only using the unicode utf8 \u*** worked for me.

Glad it works for you ! Cheers.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.