Macrons in RMarkdown PDF Graphs with Cairo_pdf

Other Unicode May Also Apply

I stayed up way too late last night working on something, but the thing that finally got me to go to bed was the following warning message when test-compiling the pdf:

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : conversion
## failure on 'Māori' in 'mbcsToSbcs': dot substituted for <c4>

For those who don’t know, R has a problem with displaying unicode in graphs, particularly in a pdf context. In this case, aside from the repeated warnings above spammed into the document itself, I was getting the following in my legends:

ggplot2 legend, where the ā in Māori has been replaced with ‘..’

Not at all what you want!

As it happens it’s Te Wiki o Te Reo Māori (Māori Language Week) this week, but regardless of the time of year failing to render macrons is unprofessional enough without mangling them like this.

When I went to bed I’d been trying the suggestions in this article by Paul Murrell and coming up largely blank, but a new morning is a new you and I was able to find the answer in a stackoverflow question asking for something slightly different.

Basically, what you want to use is the cairo_pdf device for all plots in the pdf output, and you can do that with the (in my opinion insufficiently documented, but that’s another story) YAML header like so:

title: "Cairo stuff"
    dev: cairo_pdf
Macron in Māori is now present!


As an aside, I need to learn how to insert macrons in typed text in Windows. I know how to do it with the compose key on Linux, my usual OS, but Windows isn’t so kind.

File under: