开发者

how to show $\{ X_t \}$ in the title of a plot of R

How to show $\{ X_t \}$ of Latex in the title of a plot of R?

For example

 plot(slot(x,"GRID"),slot(x,"PATH"),type="l", x开发者_高级运维lab="Time t",ylab="X",
 main=paste("Simulation of \{X_t\}"))

Thanks!


Assuming you will provide meaningful arguments for the slot expressions, then I think there is a reasonable chance that this is what you want:

plot(1:10,1:10,type="l", xlab="Time t",ylab="X",
      main=expression("Simulation of {"*X[t]*"}"))

This is a plotmath expression that presents "t" as a subscript of "X" and that expression is enclosed in curley braces. If I have misread your request, then note that the "*" character is a separator in the plotmath syntax and the braces are simply characters than can be deleted. (The LaTeX expressions don't make a lot of sense to those of us who just use the plotmath syntax, so describing what you want in prose or mathematical jargon would work better for any clarifications.)


To have R emulate LaTeX typesetting, see the examples and methods described in ?plotmath.

To actually have LaTeX typeset your plot text, use the tikz() graphics device provided by the tikzDevice package.


The group() plotmath function can be used to formalise DWin's answer. This solution has the advantage (IMHO) of not using strings as part of the expression. Instead we use the ~ operator to add spacing (whitespace is ignored).

plot(1:10, 1:10, type = "l", xlab = "Time t", ylab = "X",
     main=expression(Simulation ~ of ~ group("{", X[t], "}")))

The bgroup() plotmath function provides scalable delimiters but is used in the same manner as the example code above.

Edit (In response to ran2's comment): The same approaches can be used in ggplot and lattice, using the power of plotmath, just as with base graphics. E.g.

require(ggplot2)
df <- data.frame(A = 1:10, B = 1:10)
qplot(A, B, data = df,
      main = expression(Simulation ~ of ~ group("{", X[t], "}")))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜