私は同等の小さな問題を抱えていますが、誰かが私に解決策を提供できれば、それは私にとって大きな助けになるでしょう. ギリシャ文字のラムダを、knitr でコンパイルされた *.Rnw ファイル内のプロットの凡例のタイトルとして使用したいと考えています。codejunk にオプション dev='tikz' がなければ、ギリシャ文字のラムダをオプション title=expression(lambda) で書いても問題ありません。コードジャンクのオプションとして dev='tikz' を追加すると、これは機能しなくなります。
これまでのところ、コードジャンクで dev='tikz' を使用すると、文字列 "lambda" しか書き込めませんが、グラフの凡例のタイトルとしてギリシャ文字を書くことはできません。以下の *.Rnw ファイルをダウンロードし、knitr を使用してコンパイルして、説明されている問題をよりよく理解してください。
よろしくお願いいたします。
ブローゼル
\documentclass{article}
\title{How to write greek letters in R graphs using the tikz environment with \textbf{knitr}?}
\author{broesel}
\date{\today}
\begin{document}
\maketitle
In Figure \ref{fig:barplot} a simple graph is plotted using \textbf{knitr}.
In order to print the legend of the graph \texttt{legend()} was used.
The option \texttt{title=expression(lambda)} was used in order to write the greek letter $\lambda$ as the title of the legend.
<<barplot, fig.cap="A simple barplot having $\\lambda$ as legend title">>=
a <- c(10, 9, 6)
b <- c(8, 7, 4)
c <- rbind(a,b)
barplot(c, beside=T, ylim=c(0,12), col=c("grey", "black"))
legend("topright", c("yes", "no"),
fill=c("grey", "black"), title=expression(lambda))
@
In Figure \ref{fig:plot_tikz} the option \texttt{dev='tikz'} was used in the code chunk, in order to use the same font in the graphs as in the rest of the document, which you can see especially if you compare the y-axes and the legends of Figures \ref{fig:barplot} and \ref{fig:plot_tikz}.
Unfortunately when I use the option \texttt{title=expression(lambda)} in Figure \ref{fig:plot_tikz}, to show the greek letter $\lambda$ as the legend title, I get an error message.
So far I was only able to write "lambda" as the legend title.
So here is my question: How can I write the greek letter $\lambda$ and not "lambda" as the legend title of Figure \ref{fig:plot_tikz}?
<<plot_tikz, fig.cap="A barplot with tikz having ''lambda'' as legend title", dev='tikz'>>=
a <- c(10, 9, 6)
b <- c(8, 7, 4)
c <- rbind(a,b)
barplot(c, beside=T, ylim=c(0,12), col=c("grey", "black"))
legend("topright", c("yes", "no"),
fill=c("grey", "black"), title="lambda")
@
\end{document}