【发布时间】:2014-03-18 11:27:42
【问题描述】:
我通常使用 R 中的 scales 包在我的 ggplots 的 y 轴上给出计数数据的百分比。但是,当我尝试在 knitr 中执行此操作时,由于图中的百分比符号而出现错误:
Error in getMetricsFromLatex(TeXMetrics) :
TeX was unable to calculate metrics for the following string or character:
0%
我可以使用正常的计数轴生存,但更喜欢 %.有没有办法解决这个问题?
这是一个可重现的示例(删除+ scale_y_continuous(label=percent) 给出了一个可编译的示例):
\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
<<packages, echo=F>>=
library(ggplot2)
library(scales)
@
<<chunkopts, echo=F>>=
opts_chunk$set(echo=F, cache=T, autodep=T, fig.width = 9/1.5, fig.height=5/1.5,
fig.align="center", dev="tikz", fig.pos="h!tbp", warning=F, message=F)
dep_auto()
@
<<mydata>>=
mydata <- data.frame(
X = letters[1:10],
Y = sample(c("yes", "no"), 100, replace = TRUE))
@
<<plot>>=
ggplot(mydata, aes(X, fill = Y)) + geom_bar(position = "fill") +
scale_y_continuous(label=percent)
@
\end{document}
我正在使用 TexShop 编译我的 .Rnw 文件。
【问题讨论】: