0

在一个 Knitr 文档中,我使用了一个自定义标签函数,它输出了一些 LaTeX 代码(这里没用,只是为了说明问题)。在正常图中,一切都很好:R 设法正确猜测输出的指标并留下合理的空间(中间图)。但是当使用构面时,这些指标只是使用纯字符串,而不是像我们期望的非 LaTeX 输出设备(最后一个图)那样将其解释为 LaTeX(第一个图)。

如何说服 ggplot始终将我的标签解释为 LaTeX 并使用智能指标?

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{siunitx}
\begin{document}
\begin{frame}
<<dev='tikz', echo=F, fig.height=1.5>>=
library(ggplot2)

mylabel <- function() {
  function(xs) { sprintf("\\ensuremath{\\num{%g}}",xs) }
}
data <- data.frame(x=c(1,10), y=c(1,10), kind=c("a","a"))

ggplot(data,aes(x=x,y=y)) + geom_point() +
  scale_y_continuous(labels=mylabel()) +
  facet_grid(~ kind)
@

<<dev='tikz', echo=F, fig.height=1.5>>=
ggplot(data,aes(x=x,y=y)) + geom_point() +
  scale_y_continuous(labels=mylabel())
@

<<echo=F, fig.height=1.5>>=
ggplot(data,aes(x=x,y=y)) + geom_point() +
  scale_y_continuous(labels=mylabel())
@
\end{frame}
\end{document}

在此处输入图像描述

4

1 回答 1

0

我真的不知道这是否有帮助...

但是你看过这个帖子吗? 如何在 ggplot2 图例中使用下标 [R]

您是否尝试过使用:

scale_y_continuous(labels=c(expression(paste(_________)), expression(paste(_________))))

______你想要的表达在哪里?

于 2014-12-03T01:20:31.660 回答