我在让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}但是没有输出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 the package.
The contents of the LaTeX log of the aborted run have been printed above,
it may contain additional details as to why the metric calculation failed.
Calls: knit ... widthDetails.text -> grid.Call -> <Anonymous> -> getMetricsFromLatex
Execution halted这个问题已经被here处理过了,但是提出的解决方案对我不起作用。有什么想法吗?
发布于 2014-02-11 20:07:16
也许是与您的简单示例中未包含的另一个包冲突?对我来说,由于包xcolor和tikz之间的一些冲突,我收到了这个错误消息。我在调用Tikz之前调用了xcolor,没有问题,但是一旦我在块选项中设置了dev="tikz",我就得到了与您相同的错误。一旦我移除了\usepackage{xcolor},一切都正常了。
发布于 2016-03-24 08:28:23
我在R代码中添加了
options(tikzMetricPackages = c("\\usepackage[utf8{inputenc}",
"\\usepackage[T1]{fontenc}", "\\usetikzlibrary{calc}", "\\usepackage{amssymb}"))source
https://stackoverflow.com/questions/21542556
复制相似问题