Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

utf8 in plot labels using knitr

Tags:

plot

r

knitr

Can't compile the following Rnw document into pdf using knitr

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<>>=
hist(rnorm(100),main="Гистограмма")
@

\end{document}

With labels in English everything is ok.


Edit 1: Now i have two versions of pdf. In the first one letters are replaced by points.

In the second one all letters are overlapped. The second one is produced using addtional code chunk

<<>>=
pdf.options(encoding = "CP1251")
@

I am using Ubuntu 12.04 + R 2.14 + Texlive.


Edit 2:

For the moment i've found the following partial solution:

<<>>=
cairo_pdf("figure.pdf")
hist(rnorm(100),main="Гистограмма")
dev.off()
@
\includegraphics{figure.pdf}

Edit 3:

Using the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<dev='cairo_pdf'>>=
hist(rnorm(100),main="Гистограмма")
@

\end{document}

I obtain a CORRECT histogram, with a lot of WARNINGS. How to avoid or at least suppress them?


Finally! Ura!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<dev='cairo_pdf',warning=FALSE>>=
hist(rnorm(100),main="Гистограмма")
@

\end{document}

Could i avoid warnings? Can someone explain me all that stuff with encodings and warnings?

like image 318
Roah Avatar asked Oct 06 '22 09:10

Roah


1 Answers

You may need to set pdf.options(encoding = 'your_encoding'); see https://github.com/yihui/knitr/issues/172 I'm not entirely sure what exactly the encoding should be here.

like image 70
Yihui Xie Avatar answered Oct 10 '22 03:10

Yihui Xie