Try generating this figure with cairo_pdf()
.
cairo_pdf('test.pdf', family="Helvetica")
plot(1:10, (1:10)^2, xlab=enc2utf8("ąśćźół"))
dev.off()
It may be important to change the font family
to one of which knows about regional characters (I'm using Polish letters above). For OS X, this list may give you a hint on font family selection.
Now let's set up knitr
to use these settings. Create an uncached code chunk at the beginning of the document with calls to:
library("knitr")
library("tikzDevice")
opts_chunk$set(
dev='cairo_pdf',
dev.args=list(family='DejaVu Sans')
#out.width='5in',
#fig.width=5,
#fig.height=5/sqrt(2),
#fig.path='figures-knitr/',
#fig.align='center',
)
(I've commented out the options which are meaningless here, but which you may also be interested in some day). You may find more details on chunk options here.
Here is an exemplary .Rnw
file that (at least on my Linux) produces correct results:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[T1,plmath]{polski}
\usepackage[polish]{babel}
\begin{document}
<<cache=FALSE,echo=FALSE,message=FALSE>>=
options(Encoding="UTF-8")
library("knitr")
library("tikzDevice")
opts_chunk$set(
dev='cairo_pdf',
dev.args=list(family='Helvetica')
#out.width='5in',
#fig.width=5,
#fig.height=5/sqrt(2),
#fig.path='figures-knitr/',
#fig.align='center',
)
@
<<>>=
plot(1:10, (1:10)^2, xlab="ąśćźół")
@
\end{document}