小编ben*_*ben的帖子

使用knitr在LaTeX文档中使用tikzDevice的R图

我在制作ggplot2,tikzDevice和knitr时遇到了问题.我正在使用RStudio,并尝试在Latex文档中包含一些R图形.我用了一个非常简单的例子:

\documentclass{article} 

\begin{document} 

\begin{figure} 
<<fig1,eval=TRUE,echo=FALSE,dev='tikz'>>= 
library(ggplot2)
library(tikzDevice)
qplot(displ, hwy, data = mpg, colour = factor(cyl)) 
@ 
\end{figure} 

\end{document}
Run Code Online (Sandbox Code Playgroud)

但是没有输出pdf,我收到以下错误消息:

Error in getMetricsFromLatex(TeXMetrics) : 
TeX was unable to calculate metrics for the following string
or character:

    hwy

Common reasons for failure include:
  * The string contains a character which is special to LaTeX unless
    escaped properly, such as % or $.
  * The string makes use of LaTeX commands provided by a package and
    the tikzDevice was not told to load …
Run Code Online (Sandbox Code Playgroud)

latex r tikz ggplot2 knitr

7
推荐指数
1
解决办法
3343
查看次数

标签 统计

ggplot2 ×1

knitr ×1

latex ×1

r ×1

tikz ×1