问题描述
我想在 R 的情节标题中创建乳胶风格的数学.绘图数学工具 有一个有用但有限的表达式子集,它们可以显示,并使用非乳胶语法和样式.
I'd like to create latex-style math in plot titles in R. The plotmath tools have a useful but limited subset of expressions they can display, and use non-latex syntax and style.
例如,我想在图的标题中打印方程 $mathrm{d} mathbf{x} = a [heta - mathbf{x}] mathrm{d} t$,并且仍然评估某些变量的值.我最好的解决方案是非常麻烦:
For instance, I would like to print the equation $mathrm{d} mathbf{x} = a [heta - mathbf{x}] mathrm{d} t$ in the title of the plot, and still evaluate the value of certain variables. The best solution I have is the very cumbersome:
lambda <- 4
plot(1:10,1:10)
mtext(bquote(paste(d*bolditalic(x)[italic(t)] == alpha*(theta - bolditalic(x)[italic(t)] )*d*italic(t) + .(lambda) * d * italic(B)[italic(t)] )), line=2.25,cex=2)
或
require(ggplot2)
qplot(1:10, 1:10) + opts(title=bquote(paste(d*bolditalic(x)[italic(t)] == alpha*(theta - bolditalic(x)[italic(t)] )*d*italic(t) + .(lambda) * d * italic(B)[italic(t)] )), line=2.25,cex=2)
这个问题 几乎解决了这个问题,但是我失去了 bquote 显示的能力变量的数值(在我的示例中为 lambda).有没有办法将这些组合起来,以便我可以使用斜体希腊字母(变量的标准格式,例如由 tex 完成)并以特定值进行评估?
This question almost solves this, but I loose the ability of bquote to display the numerical value of a variable (lambda in my example). Is there a way to combine these so I can have italic greek letters (the standard format for variables, e.g. as done by tex) and evaluate at specific values?
有没有更好的方法可以让我简单地为方程编写 tex 语法并将它们添加到我的图表中?
Is there a much better way where I can simple write tex-syntax for equations and add them to my graphs?
推荐答案
您可能需要查看 tikzDevice
包(或查看 它的小插图优先),它提供了一种在 R 图形中编写 LaTeX 数学的自然方式.
You may want to check out the tikzDevice
package (or take a look at its vignette first), which provides a natural way to write LaTeX math in R graphics.
我也有这里有一个简单的例子.
这是另一个例子:
library(tikzDevice)
library(ggplot2)
tikz('math.tex', standAlone = TRUE, width = 4, height = 4)
qplot(1:10, 1:10,
main = '$\mathrm{d} \mathbf{x} = a [\theta - \mathbf{x}] \mathrm{d} t$')
dev.off()
如果你运行 pdflatex math.tex
会产生这个:
which produces this if you run pdflatex math.tex
:
这篇关于情节标题中的斜体希腊字母/乳胶式数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!