如何使用knitr的tikz环境在R图中书写希腊字母?

如何使用knitr的tikz环境在R图中书写希腊字母?,r,latex,knitr,tikz,R,Latex,Knitr,Tikz,我有一个类似的小问题,但如果有人能为我提供一个解决方案,这将是一个很大的帮助。我希望使用knitr编译的*.Rnw文件中的希腊字母lambda作为情节图例的标题。如果codejunk中没有选项dev='tikz',那么使用选项title=expression(lambda)编写希腊字母lambda是没有问题的。如果我在codejunk中添加dev='tikz'作为选项,这将不再有效 到目前为止,如果我在代码中使用dev='tikz',我只能写字符串“lambda”,但不能写希腊字母作为图表的图例

我有一个类似的小问题,但如果有人能为我提供一个解决方案,这将是一个很大的帮助。我希望使用knitr编译的*.Rnw文件中的希腊字母lambda作为情节图例的标题。如果codejunk中没有选项dev='tikz',那么使用选项title=expression(lambda)编写希腊字母lambda是没有问题的。如果我在codejunk中添加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}
\documentclass{article}
\标题{如何使用tikz环境和\textbf{knitr}在R图中书写希腊字母?}
\作者{broesel}
\日期{\今天}
\开始{document}
\maketitle
在图\ref{fig:barplot}中,使用\textbf{knitr}绘制简单图形。
为了打印图形的图例,使用了\texttt{legend()}。
选项\texttt{title=expression(lambda)}用于将希腊字母$\lambda$作为图例的标题。
=

正确的答案是写
“$\\lambda$”
tikz
是由
latex
或其变体处理的,因此,正如您在图形标题中有
$\\lambda$
一样,
“$\\lambda$”
作为您的标题,应该适当地处理。我一直很亲密。我已经在使用$\\lambda$,因为我有同样的想法,但忘记了“”。非常感谢你的提示!如果你们中的任何一位都能写一个答案并将这个问题标记为已回答,那就太好了。