是否可以在 x 轴值中添加数学符号?
Is it possible to add mathematical symbols in x-axis values?
我没有在 x 标签中添加数学符号,而是尝试在 0 处添加 $t_[1,n]$、$t_[2,n]$ 和 $t_[3,n]$ 符号、x 轴值分别为 40 和 85 个点。为此,我的代码是
m=c(rnorm(40,0,.5),rnorm(45,5,.5));
plot(rep(1:85,1), m, type="l", lty=1, xaxt='n', yaxt='n',ann=FALSE, col=4);
windowsFonts(script=windowsFont("Script MT Bold"));
title(xlab=c(expression(t[1,n]), expression(t[2,n]), expression(t[3,n])), family="script");
也许可以试试 ggplot2
,就像这里:
library("ggplot2")
x <- 1:85
y <- c(rnorm(40,0,.5), rnorm(45,5,.5));
dane <- data.frame(x=x, y=y)
ggplot(dane, aes(x=x, y=y))+
geom_line()+
theme_bw()+
scale_x_discrete(breaks=c(1, 40, 85),
labels=c(expression(t[paste("[", 1, ",", n, "]")]),
expression(t[paste("[", 2, ",", n, "]")]),
expression(t[paste("[", 3, ",", n, "]")])))
使用 axis
代替 title
。
axis(side = 1, at = c(0, 40, 85),
labels = c(expression(t["1,n"]),
expression(t["2,n"]),
expression(t["3,n"])))
我没有在 x 标签中添加数学符号,而是尝试在 0 处添加 $t_[1,n]$、$t_[2,n]$ 和 $t_[3,n]$ 符号、x 轴值分别为 40 和 85 个点。为此,我的代码是
m=c(rnorm(40,0,.5),rnorm(45,5,.5));
plot(rep(1:85,1), m, type="l", lty=1, xaxt='n', yaxt='n',ann=FALSE, col=4);
windowsFonts(script=windowsFont("Script MT Bold"));
title(xlab=c(expression(t[1,n]), expression(t[2,n]), expression(t[3,n])), family="script");
也许可以试试 ggplot2
,就像这里:
library("ggplot2")
x <- 1:85
y <- c(rnorm(40,0,.5), rnorm(45,5,.5));
dane <- data.frame(x=x, y=y)
ggplot(dane, aes(x=x, y=y))+
geom_line()+
theme_bw()+
scale_x_discrete(breaks=c(1, 40, 85),
labels=c(expression(t[paste("[", 1, ",", n, "]")]),
expression(t[paste("[", 2, ",", n, "]")]),
expression(t[paste("[", 3, ",", n, "]")])))
使用 axis
代替 title
。
axis(side = 1, at = c(0, 40, 85),
labels = c(expression(t["1,n"]),
expression(t["2,n"]),
expression(t["3,n"])))