1

I'm using Lyx 2.1.2 with knitr (not sure of the version) and R 3.1.2 on Fedora 20 to produce documents with various graphs and tables. After much trial and error I worked out at least one way to get Japanese text into the body of my documents, but am having trouble with graph labels and annotations generated by R/knitr, and wondered if there is a standard setup?

To enter Japanese text into the body of the document I add:

\usepackage{CJK}

to the LaTex preamble, and then bracket my document with ERT:

\begin{CJK}{UTF8}{min}
:
説明
:
\end{CJK}

This works fine and produces a PDF file with the Japanese text. But if I now add a knitr chunk:

<<echo=FALSE>>=
require(methods,quietly=TRUE)
library(ggplot2)

date <- seq(as.Date("2015-01-01"),as.Date("2015-01-31"),by="1 day")
median <- abs(rnorm(n=31))
q1 <- data.frame(date,median)

g <- ggplot(q1,aes(x=date,y=median))
g <- g + geom_bar(stat="identity",position="dodge",fill="#00BA38")
g <- g + xlab("日付") + ylab("数")
g <- g + theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1))
g

between the bracketing ERT, the generated PDF file contains almost two pages of error messages like this, multiple warnings for each byte of the UTF8 representation of the axis labels:

## Warning in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, conversion failure on '数' in 'mbcsToSbcs': dot substituted for <e6>

and, as it says, with dots substituted for the Japanese text. If I replace the Japanese labels with English, everything works fine, so it seems I need something extra to help knitr and Lyx communicate, but what?

Thanks for any pointers!

user4294565
  • 131
  • 5

0 Answers0